Skip to content

Commit 7dd8d69

Browse files
committed
added ability to backup (or not) to iCloud on iOS
1 parent 505747b commit 7dd8d69

5 files changed

Lines changed: 29 additions & 6 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
modules/commonjs/To.ImageCache/0.2.0/manifest
3+
4+
modules/commonjs/To.ImageCache/0.2.0/README.md
5+
6+
modules/commonjs/To.ImageCache/0.2.0/To.ImageCache.js

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ All current properties available shown below
1919
require('To.ImageCache').config({
2020
debug: true, //default "false"
2121
expireTime: 100000, // time in seconds, default 43200 = 12 hours
22-
folder: 'CustomFolder' // folder to store the cache in, default "ToCache"
22+
folder: 'CustomFolder', // folder to store the cache in, default "ToCache"
23+
remoteBackup: true // iOS Only do you want the images to be backed up to iCloud?
2324
});
2425
```
2526

27+
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
28+
2629
All available images will be stored in Properties
2730

2831
```js

To.ImageCache.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var c = {
22
folder: 'ToCache',
33
expireTime: 43200, // half a day (in seconds)
4-
debug: true
4+
debug: false, // does console.log debug
5+
remoteBackup: true // do you want the file(s) to be backed up to a remote cloud, like iCloud on iOS? Doesn't work on Android
56
};
67

78
var fileList = Ti.App.Properties.getList('To.ImageCache.ImageList',[]);
@@ -11,6 +12,9 @@ var fileList = Ti.App.Properties.getList('To.ImageCache.ImageList',[]);
1112
* @param {Object} Config Object as per spec
1213
*/
1314
var config = function(config){
15+
if (!config){
16+
return;
17+
}
1418
if (config.debug){
1519
Ti.API.info('TIC - setting config');
1620
}
@@ -125,6 +129,11 @@ var removeFile = function(filename){
125129
}
126130
};
127131

132+
function md5FileName(url){
133+
var filename = Ti.Utils.md5HexDigest(url);
134+
return filename;
135+
}
136+
128137
/**
129138
* Remove a file based on URL from cache.
130139
* Useful if you don't know the filename
@@ -134,7 +143,7 @@ var removeRemote = function(url){
134143
if (c.debug)
135144
Ti.API.info('TIC - removing file based on URL');
136145

137-
var filename = Ti.Utils.md5HexDigest(url);
146+
var filename = md5FileName(url);
138147
removeFile(filename);
139148
};
140149

@@ -158,6 +167,11 @@ var storeFile = function(filename, blob){
158167

159168
var path = Ti.Filesystem.applicationDataDirectory + c.folder;
160169
var file = Ti.Filesystem.getFile(path, filename);
170+
171+
if (OS_IOS && c.hasOwnProperty(remoteBackup)){
172+
file.remoteBackup = c.remoteBackup;
173+
}
174+
161175
file.write(blob);
162176
// destroy file after it has been saved
163177
file = null;
@@ -204,7 +218,7 @@ var remoteImage = function(url){
204218
Ti.API.info('remote image');
205219
}
206220
// calculate local filename
207-
var filename = Ti.Utils.md5HexDigest(url);
221+
var filename = md5FileName(url);
208222
Ti.API.info(filename);
209223

210224
if (hasFile(filename)){
@@ -244,7 +258,7 @@ var cache = function(url, timeout, cb){
244258
var timeout = timeout || 30000;
245259

246260
// if file is already cached, don't do so again
247-
var filename = Ti.Utils.md5HexDigest(url);
261+
var filename = md5FileName(url);
248262
if (hasFile(filename)){
249263
if (c.debug)
250264
Ti.API.info('TIC - file already cached');
6.16 KB
Binary file not shown.

manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 0.1.2
1+
version: 0.2.0
22
description: A simple Commonjs module to cache images a little less temporarily
33
author: Rene Pot
44
license: Apache 2.0

0 commit comments

Comments
 (0)