@Test public void dontReadFromMemoryCache() { int memoryPolicy = 0; memoryPolicy |= MemoryPolicy.NO_CACHE.index; assertThat(MemoryPolicy.shouldReadFromMemoryCache(memoryPolicy)).isFalse(); }
@Test public void writeToMemoryCache() { int memoryPolicy = 0; memoryPolicy |= MemoryPolicy.NO_CACHE.index; assertThat(MemoryPolicy.shouldWriteToMemoryCache(memoryPolicy)).isTrue(); } }
@Test public void readFromMemoryCache() { int memoryPolicy = 0; memoryPolicy |= MemoryPolicy.NO_STORE.index; assertThat(MemoryPolicy.shouldReadFromMemoryCache(memoryPolicy)).isTrue(); }
@Test public void dontWriteToMemoryCache() { int memoryPolicy = 0; memoryPolicy |= MemoryPolicy.NO_STORE.index; assertThat(MemoryPolicy.shouldWriteToMemoryCache(memoryPolicy)).isFalse(); }
private void performRemoteViewInto(Request request, RemoteViewsAction action) { if (shouldReadFromMemoryCache(request.memoryPolicy)) { Bitmap bitmap = picasso.quickMemoryCacheCheck(action.request.key); if (bitmap != null) { action.complete(new RequestHandler.Result(bitmap, MEMORY)); return; } } if (placeholderResId != 0) { action.setImageResource(placeholderResId); } picasso.enqueueAndSubmit(action); } }
void performComplete(BitmapHunter hunter) { if (shouldWriteToMemoryCache(hunter.data.memoryPolicy)) { RequestHandler.Result result = hunter.getResult(); if (result != null) { Bitmap bitmap = result.getBitmap(); if (bitmap != null) { cache.set(hunter.getKey(), bitmap); } } } hunterMap.remove(hunter.getKey()); deliver(hunter); }
Result hunt() throws IOException { if (shouldReadFromMemoryCache(data.memoryPolicy)) { Bitmap bitmap = cache.get(key); if (bitmap != null) {
/** * Synchronously fulfill this request. Must not be called from the main thread. */ @Nullable // TODO make non-null and always throw? public Bitmap get() throws IOException { long started = System.nanoTime(); checkNotMain(); if (deferred) { throw new IllegalStateException("Fit cannot be used with get."); } if (!data.hasImage()) { return null; } Request request = createRequest(started); Action action = new GetAction(picasso, request); RequestHandler.Result result = forRequest(picasso, picasso.dispatcher, picasso.cache, picasso.stats, action).hunt(); Bitmap bitmap = result.getBitmap(); if (bitmap != null && shouldWriteToMemoryCache(request.memoryPolicy)) { picasso.cache.set(request.key, bitmap); } return bitmap; }
if (shouldReadFromMemoryCache(request.memoryPolicy)) { Bitmap bitmap = picasso.quickMemoryCacheCheck(request.key); if (bitmap != null) {
if (shouldReadFromMemoryCache(request.memoryPolicy)) { Bitmap bitmap = picasso.quickMemoryCacheCheck(request.key); if (bitmap != null) {
void resumeAction(Action action) { Bitmap bitmap = null; if (shouldReadFromMemoryCache(action.request.memoryPolicy)) { bitmap = quickMemoryCacheCheck(action.request.key); } if (bitmap != null) { // Resumed action is cached, complete immediately. deliverAction(new RequestHandler.Result(bitmap, MEMORY), action, null); if (loggingEnabled) { log(OWNER_MAIN, VERB_COMPLETED, action.request.logId(), "from " + MEMORY); } } else { // Re-submit the action to the executor. enqueueAndSubmit(action); if (loggingEnabled) { log(OWNER_MAIN, VERB_RESUMED, action.request.logId()); } } }
if (shouldReadFromMemoryCache(request.memoryPolicy)) { Bitmap bitmap = picasso.quickMemoryCacheCheck(request.key); if (bitmap != null) {