use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class SmallCacheIfRequestedDiskCachePolicyTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
List<CacheKey> keys = new ArrayList<>(1);
keys.add(new SimpleCacheKey("http://dummy.uri"));
mCacheKey = new MultiCacheKey(keys);
when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);
when(mImageRequest.getCacheChoice()).thenReturn(ImageRequest.CacheChoice.DEFAULT);
when(mImageRequest.isDiskCacheEnabled()).thenReturn(true);
mIsCancelled = new AtomicBoolean(false);
mSmallCacheIfRequestedDiskCachePolicy = new SmallCacheIfRequestedDiskCachePolicy(mDefaultBufferedDiskCache, mSmallImageBufferedDiskCache, mCacheKeyFactory);
}
use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class SplitCachesByImageSizeDiskCachePolicy method createAndStartCacheReadTask.
@Override
public Task<EncodedImage> createAndStartCacheReadTask(ImageRequest imageRequest, Object callerContext, final AtomicBoolean isCancelled) {
final CacheKey cacheKey = mCacheKeyFactory.getEncodedCacheKey(imageRequest, callerContext);
final boolean alreadyInSmall = mSmallImageBufferedDiskCache.containsSync(cacheKey);
final boolean alreadyInMain = mDefaultBufferedDiskCache.containsSync(cacheKey);
final BufferedDiskCache firstCache;
final BufferedDiskCache secondCache;
if (alreadyInSmall || !alreadyInMain) {
firstCache = mSmallImageBufferedDiskCache;
secondCache = mDefaultBufferedDiskCache;
} else {
firstCache = mDefaultBufferedDiskCache;
secondCache = mSmallImageBufferedDiskCache;
}
return firstCache.get(cacheKey, isCancelled).continueWithTask(new Continuation<EncodedImage, Task<EncodedImage>>() {
@Override
public Task<EncodedImage> then(Task<EncodedImage> task) throws Exception {
if (isTaskCancelled(task) || (!task.isFaulted() && task.getResult() != null)) {
return task;
}
return secondCache.get(cacheKey, isCancelled);
}
});
}
use of com.facebook.cache.common.CacheKey in project remusic by aa112901.
the class PlaylistActivity method setAlbumart.
private void setAlbumart() {
playlistTitleView.setText(playlistName);
if (albumPath == null) {
albumArtSmall.setImageResource(R.drawable.placeholder_disk_210);
} else {
albumArtSmall.setImageURI(Uri.parse(albumPath));
}
try {
if (isLocalPlaylist && !URLUtil.isNetworkUrl(albumPath)) {
new setBlurredAlbumArt().execute(ImageUtils.getArtworkQuick(PlaylistActivity.this, Uri.parse(albumPath), 300, 300));
L.D(d, TAG, "albumpath = " + albumPath);
} else {
// drawable = Drawable.createFromStream( new URL(albumPath).openStream(),"src");
ImageRequest imageRequest = ImageRequest.fromUri(albumPath);
CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest);
BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
File file = ((FileBinaryResource) resource).getFile();
if (file != null)
new setBlurredAlbumArt().execute(ImageUtils.getArtworkQuick(file, 300, 300));
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class DiskStorageCacheTest method testCacheEventListener.
@Test
public void testCacheEventListener() throws Exception {
// 1. Add first cache file
CacheKey key1 = new SimpleCacheKey("foo");
int value1Size = 101;
byte[] value1 = new byte[value1Size];
// just so it's not all zeros for the equality test below.
value1[80] = 'c';
BinaryResource resource1 = mCache.insert(key1, WriterCallbacks.from(value1));
verifyListenerOnWriteAttempt(key1);
String resourceId1 = verifyListenerOnWriteSuccessAndGetResourceId(key1, value1Size);
BinaryResource resource1Again = mCache.getResource(key1);
assertEquals(resource1, resource1Again);
verifyListenerOnHit(key1, resourceId1);
BinaryResource resource1Again2 = mCache.getResource(key1);
assertEquals(resource1, resource1Again2);
verifyListenerOnHit(key1, resourceId1);
SimpleCacheKey missingKey = new SimpleCacheKey("nonexistent_key");
BinaryResource res2 = mCache.getResource(missingKey);
assertNull(res2);
verifyListenerOnMiss(missingKey);
mCache.clearAll();
verify(mCacheEventListener).onCleared();
verifyNoMoreInteractions(mCacheEventListener);
}
use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class DiskStorageCacheTest method testHasKeyWithoutPopulateAtStartupWithAwaitingIndex.
@Test
public void testHasKeyWithoutPopulateAtStartupWithAwaitingIndex() throws Exception {
// A new cache object in the same directory. Equivalent to a process restart.
// Index may not yet updated.
DiskStorageCache cache2 = createDiskCache(mStorage, false);
CacheKey key = putOneThingInCache();
// Wait for index populated in cache before use of cache
cache2.awaitIndex();
assertTrue(cache2.isIndexReady());
assertTrue(cache2.hasKey(key));
assertTrue(cache2.hasKeySync(key));
}
Aggregations