Created
January 14, 2012 08:52
-
-
Save hakobera/1610744 to your computer and use it in GitHub Desktop.
Titanium で ImageView のキャッシュを起動時に消す (for iOS only)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 指定した時間更新されていない画像キャッシュを削除する。 | |
* iOS にのみ対応。 | |
* | |
* @param {Number} expiredTime キャッシュ保持期限 (ms) | |
*/ | |
module.exports = function(expiredTime) { | |
var cachePath = Ti.Filesystem.applicationDataDirectory + '../Library/Caches/', | |
cacheDir = Ti.Filesystem.getFile(cachePath), | |
now = new Date().getTime(); | |
if (cacheDir) { | |
var files = cacheDir.getDirectoryListing(); | |
if (files) { | |
for (var i = 0, l = files.length; i < l; ++i) { | |
var file = Ti.Filesystem.getFile(cachePath, files[i]), | |
filename = file.name; | |
// 画像キャッシュは '.' で終わるファイル名で保存されている | |
if (filename[filename.length - 1] === '.') { | |
if (now - file.modificationTimestamp() > expiredTime) { | |
Ti.API.debug(files[i]); | |
file.deleteFile(); | |
} | |
} | |
} | |
} | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 7日間更新がない画像キャッシュファイルを削除する | |
require('deleteImageCache')(/*7days =*/7 * 24 * 60 * 60 * 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment