Created
April 1, 2011 16:38
-
-
Save abscondment/898451 to your computer and use it in GitHub Desktop.
purgeDiskCache
This file contains hidden or 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
def self.cache_dir(c:Context):File | |
@cache_dir ||= File.new(c.getCacheDir, "lazy_image_cache") | |
@cache_dir.mkdirs unless @cache_dir.exists | |
@cache_dir | |
end | |
def self.purgeDiskCache(c:Context):void | |
thread = Thread.new do | |
# 8 hours | |
oldest_acceptable = System.currentTimeMillis - long(28800000) | |
d = LazyImageView.cache_dir(c) | |
files = d.listFiles unless d.nil? | |
unless files.nil? | |
files.each do |f| | |
begin | |
# Skip nils, directories, and current files. | |
next if f.nil? || (!f.isFile) || f.lastModified >= oldest_acceptable | |
Log.v "LazyImageView", "D " + f.getCanonicalPath | |
f.delete | |
rescue IOException => e | |
Log.e "LazyImageView", "purgeDiskCache: Error checking or deleting cache file:", e | |
end | |
end | |
end | |
end | |
# Do this on a different thread | |
LazyGalleryActivity.threadPoolExecutor.execute thread | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment