titanium mobile : delete remote image cache

http://developer.appcelerator.com/question/144356/urgent-how-to-clearreset-titanium-remote-image-cache-android

この辺。

http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Filesystem

applicationCacheDirectory : StringREADONLY
Path to the application’s internal cache directory.
iosのほうはみんな違う書き方をしているけど昔は無かったのかな?

Ti.Filesystem.applicationCacheDirectory
ios : Applications/00000000-0000-0000-0000-AAAAAAAAAA/Library/Caches/
これなのでiosもあっています。
Libraryの下は
Cookies
Preferences
Caches
Private Documents
があって、Private Documents/databasename.sql という名前でsqliteが保存されていました。

画像は、普通に ハッシュ値.jpgの拡張子で保存されています。.をみて消している方は、ディレクトリを消しています。
特に問題ないと思いのですが、中に Cache.dbとかあります。手で全消ししても問題ないようです。
(十分テストが必要ですが)

androidはexternalのときの処理が必要。
androidの処理はbanzai mobileさんのやり方を利用させていただきます。

http://developer.appcelerator.com/question/144356/urgent-how-to-clearreset-titanium-remote-image-cache-android#answer-251819

ポイントは、/_tmp/remote-cache/ですね。
全消しはなんとなくあれなので、ファイルを消す処理(getFile以外)は、iosと共通で。
iosだけだとこんな感じ

dir = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory);
if( dir.exists() ){
 var files = dir.getDirectoryListing();
 for( var i in files ){
   if( files[i].match(/jpg|jpeg|png|gif/i)){
     var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory, files[i]);
     if( f.exists() ){
       f.deleteFile();
     }
   }
 }
 return true;
}

実際は、起動時は全消し、タイミングをみて、古いものを消去でしょうか。
webview を使っているとCache.dbもモリモリ貯まって行くのでサイズをみて消した方が良さそうなので
定期的に全消しに変更したいと思います。

githubにあげました。

https://github.com/junichi-otake/titanium-lib

メモ:別の話。

http://developer.appcelerator.com/question/134926/ipad-app-rejected-ios-data-storage-guidelines

This entry was posted on 水曜日, 4月 10th, 2013 at 3:01 AM and is filed under Android, iOS, Titanium. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Unityによるゲームを公開しております iOS/Android
https://itunes.apple.com/jp/app/lost-knight-3d-action/id900917032
https://play.google.com/store/apps/details?id=com.groundroad.runknight

各種開発支援・機能開発等小さいお仕事などもお請けしております。
unity開発支援, PHPシステム開発, javascript/html5 フロント開発, titanium mobileアプリ開発
お気軽にお問い合わせください
大崎・五反田近郊での対面でのお打ち合わせはいつでも可能です。