Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
to.imagecache
Advanced tools
A simple image cacher module for Titanium Applications if you want to maintain it manually
A simple CommonJS module to cache images a little less temporarily, and configurable
Add To.ImageCache
CommonJS module to your project. Either download this project, or install using gittio
gittio install To.ImageCache
Follow regular steps to include it in your project
In classic go to the Resources
folder, for Alloy go to the lib
directory of your project, then run the following command
npm install to.imagecache
Note: if your app doesn't have node_modules
yet, run npm init
first!
IMPORTANT: Version 1.0 is not backwards compatible with previous versions. Name has changed to lowercase for NPM support
The configuration is simple: No configuration is needed, unless you want to change something.
All current properties available shown below
require('to.imagecache').config({
debug: true, //default "false"
expireTime: 100000, // time in seconds, default 43200 = 12 hours
folder: 'CustomFolder', // folder to store the cache in, default "ToCache"
remoteBackup: true // iOS Only do you want the images to be backed up to iCloud?
});
The config can be changed at all times, between different files so support multiple folders, expiration times and file specfic backup properties. You only have to pass what you want to change from now on. No need to pass all config properties
If you want to make a copy of the config, so you can restore it later, use the getter
var config = require('to.imagecache').config();
All available images will be stored in Properties
Ti.App.Properties.getList('To.ImageCache.ImageList');
There is, however, no need to call this list manually unless you really want to. Best to use build in functionality
There are 2 methods to use the module.
Note: This might cause delays in your app and is only recommended for smaller images
var blob = require('to.imagecache').remoteImage('http://example.com/image.jpg');
This will cache the image the first time it is called, and the next time you request this same file it will return the same blob, but this time stored locally
This method is preferred for bigger images, as this can happen in the background
require('to.imagecache').cache('http://example.com/image.jpg');
This function will NOT return a blob, but will cache the file using XHR
.
Aditonally, you can add a timeout and callback function:
require('to.imagecache').cache('http://example.com/image.jpg', 25000, function(blob){
$.imageView.image = blob;
});
You want, of course, to clear the cache when needed. This is NOT done automatically.
The best function to call is flushExpired
require('to.imagecache').flushExpired();
This function will remove all files older than the expired time.
You can also clear all cache
require('to.imagecache').clearCache();
This will remove all cached files regardless of expired time.
You can also remove a single file by URL:
require('to.imagecache').removeRemote('http://example.com/image.jpg');
This will also NOT take expiry time in consideration
If you know the filename (which is internally generated, so you probably won't), you can remove by filename too
require('to.imagecache').removeFile('a128a10e623e08c9b5b704bf162d770e');
You can fetch the entire cache size, in bytes, from the module. This could, for example, be used to display users so they can be aware how much cache is present, and you could give the users the ability to remove cache manually
require('to.imagecache').cacheSize()
You can also, at a later point, update the config. Expire time is per-file, and stored per-file. So changing it later will not update the currently stored files. Might be usefull for different expiry times.
Also the folder can be changed multiple times. Folders are also stored per file, so changable all the time.
FAQs
A simple image cacher module for Titanium Applications if you want to maintain it manually
The npm package to.imagecache receives a total of 3 weekly downloads. As such, to.imagecache popularity was classified as not popular.
We found that to.imagecache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.