synchronized static FileLruCache getCache() throws IOException{ if (urlRedirectCache == null) { urlRedirectCache = new FileLruCache(TAG, new FileLruCache.Limits()); } return urlRedirectCache; }
synchronized static FileLruCache getCache(Context context) throws IOException{ if (imageCache == null) { imageCache = new FileLruCache(TAG, new FileLruCache.Limits()); } return imageCache; }
private synchronized static void performFirstInitialize() { if (isInitialized) { return; } handler = new Handler(Looper.getMainLooper()); Context appContext = FacebookSdk.getApplicationContext(); SharedPreferences sharedPreferences = appContext.getSharedPreferences( LIKE_ACTION_CONTROLLER_STORE, Context.MODE_PRIVATE); objectSuffix = sharedPreferences.getInt(LIKE_ACTION_CONTROLLER_STORE_OBJECT_SUFFIX_KEY, 1); controllerDiskCache = new FileLruCache(TAG, new FileLruCache.Limits()); registerAccessTokenTracker(); CallbackManagerImpl.registerStaticCallback( CallbackManagerImpl.RequestCodeOffset.Like.toRequestCode(), new CallbackManagerImpl.Callback() { @Override public boolean onActivityResult(int resultCode, Intent data) { return handleOnActivityResult( CallbackManagerImpl.RequestCodeOffset.Like.toRequestCode(), resultCode, data); } }); isInitialized = true; }
FileLruCache cache = new FileLruCache("testCacheSizeLimit", limitCacheSize(cacheSize)); try { TestUtils.clearFileLruCache(cache);
FileLruCache cache = new FileLruCache("testCacheLru", limitCacheCount(keepCount + 1)); try { TestUtils.clearFileLruCache(cache);
@Test public void testCacheClearMidBuffer() throws Exception { int dataSize = 1024; byte[] data = generateBytes(dataSize); String key = "a"; String key2 = "b"; // Limit to 2x to allow for extra header data FileLruCache cache = new FileLruCache("testCacheClear", limitCacheSize(2*dataSize)); try { TestUtils.clearFileLruCache(cache); put(cache, key, data); checkValue(cache, key, data); OutputStream stream = cache.openPutStream(key2); Thread.sleep(200); TestUtils.clearFileLruCache(cache); stream.write(data); stream.close(); assertEquals(false, hasValue(cache, key)); assertEquals(false, hasValue(cache, key2)); assertEquals(0, cache.sizeInBytesForTest()); } finally { TestUtils.clearAndDeleteLruCacheDirectory(cache); } }
final byte[] data = generateBytes(dataSize); final FileLruCache cache = new FileLruCache( "testConcurrentWritesToSameKey", limitCacheCount(count+1)); try {
@Test public void testSizeInBytes() throws Exception { int count = 17; int dataSize = 53; int cacheSize = count * dataSize; byte[] data = generateBytes(dataSize); // Limit to 2x to allow for extra header data FileLruCache cache = new FileLruCache("testSizeInBytes", limitCacheSize(2*cacheSize)); try { TestUtils.clearFileLruCache(cache); for (int i = 0; i < count; i++) { put(cache, i, data); // The size reported by sizeInBytes includes a version/size token as well // as a JSON blob that records the name. Verify that the cache size is larger // than the data content but not more than twice as large. This guarantees // that sizeInBytes is doing at least approximately the right thing. int totalDataSize = (i + 1) * dataSize; assertTrue(cache.sizeInBytesForTest() > totalDataSize); assertTrue(cache.sizeInBytesForTest() < 2 * totalDataSize); } for (int i = 0; i < count; i++) { String key = Integer.valueOf(i).toString(); checkValue(cache, key, data); } } finally { TestUtils.clearAndDeleteLruCacheDirectory(cache); } }
FileLruCache cache = new FileLruCache("testCacheCountLimit", limitCacheCount(cacheCount)); try { TestUtils.clearFileLruCache(cache);
@Test public void testCacheOutputStream() throws Exception { int dataSize = 1024; byte[] data = generateBytes(dataSize); String key = "a"; // Limit to 2x to allow for extra header data FileLruCache cache = new FileLruCache("testCacheOutputStream", limitCacheSize(2*dataSize)); try { put(cache, key, data); checkValue(cache, key, data); } finally { TestUtils.clearAndDeleteLruCacheDirectory(cache); } }
@Test public void testCacheClear() throws Exception { int dataSize = 1024; byte[] data = generateBytes(dataSize); String key = "a"; // Limit to 2x to allow for extra header data FileLruCache cache = new FileLruCache("testCacheClear", limitCacheSize(2*dataSize)); try { TestUtils.clearFileLruCache(cache); put(cache, key, data); checkValue(cache, key, data); TestUtils.clearFileLruCache(cache); assertEquals(false, hasValue(cache, key)); assertEquals(0, cache.sizeInBytesForTest()); } finally { TestUtils.clearAndDeleteLruCacheDirectory(cache); } }
@Test public void testCacheInputStream() throws Exception { int dataSize = 1024; byte[] data = generateBytes(dataSize); String key = "a"; InputStream stream = new ByteArrayInputStream(data); // Limit to 2x to allow for extra header data FileLruCache cache = new FileLruCache("testCacheInputStream", limitCacheSize(2*dataSize)); try { TestUtils.clearFileLruCache(cache); InputStream wrapped = cache.interceptAndPut(key, stream); consumeAndClose(wrapped); checkValue(cache, key, data); } finally { TestUtils.clearAndDeleteLruCacheDirectory(cache); } }
synchronized static FileLruCache getCache(Context context) throws IOException{ if (imageCache == null) { imageCache = new FileLruCache(context.getApplicationContext(), TAG, new FileLruCache.Limits()); } return imageCache; }
synchronized static FileLruCache getCache(Context context) throws IOException{ if (urlRedirectCache == null) { urlRedirectCache = new FileLruCache(context.getApplicationContext(), TAG, new FileLruCache.Limits()); } return urlRedirectCache; }
static FileLruCache getResponseCache() { if (responseCache == null) { Context applicationContext = Session.getStaticContext(); if (applicationContext != null) { responseCache = new FileLruCache(applicationContext, RESPONSE_CACHE_TAG, new FileLruCache.Limits()); } } return responseCache; }