android - Cache Strategy: If in LimitedAgeMemoryCache, load there, else load from web. Fall back to UnlimitedDiscCache on failure -
is possible above?
my scenario weather graphics urls remain same, while underlying image changes. here cases want cover: - inside same session of app (typically 2-5min), never want reload images web - after 15 minutes or so, image has changed, , if have cached version, want dump it. - when trying reload images while offline, image (including old) better no image, want show disc cache.
is setup possible? didn't seem obvious if feasible uil.
thanks great library!
i think solution you:
file cachedir = storageutils.getcachedirectory(context); // or other folder memorycacheaware<string, bitmap> memorycachecore = new lrumemorycache(4 * 1024 * 1024); // or other implementation memorycacheaware<string, bitmap> memorycache = new limitedagememorycache<string, bitmap>(memorycachecore, 15 * 60); disccacheaware disccache = new limitedagedisccache(cachedir, 15 * 60); imageloaderconfiguration config = new imageloaderconfiguration.builder(context) .memorycache(memorycache) .disccache(disccache) ... .build();
upd: uil search needed image in memory cache @ first. uil search in disc cache. , downloads image network.
if use "limited age" memory cache or disc cache bitmap or image file deleted cache after timeout (actually deleted during search in cache). logic following:
- search bitmap in memory cache
- needed bitmap there
- bitmap added cache more specified time ago
- delete memory cache, go step 2
- bitmap added cache
- get bitmap, display it. end.
- bitmap added cache more specified time ago
- no needed bitmap in cache, go step 2
- needed bitmap there
- search image file in disc cache
- needed image there
- image added cache more specified time ago
- delete disc cache, go step 3
- image added cache
- decode image bitmap, display it. end.
- image added cache more specified time ago
- no needed image in cache, go step 3
- needed image there
- download image
don't forget enable caching (in display options, displayimageoptions
).
Comments
Post a Comment