Tabnine Logo
DiskCache
Code IndexAdd Tabnine to your IDE (free)

How to use
DiskCache
in
com.bumptech.glide.load.engine.cache

Best Java code snippets using com.bumptech.glide.load.engine.cache.DiskCache (Showing top 20 results out of 315)

origin: bumptech/glide

@Test
public void get_afterDeleteDirectoryOutsideGlideAndClose_doesNotThrow() {
 DiskCache cache = DiskLruCacheWrapper.create(cacheDir, 1024 * 1024);
 cache.get(mock(Key.class));
 deleteRecursively(cacheDir);
 cache.clear();
 cache.get(mock(Key.class));
}
origin: bumptech/glide

@Test
public void testDoesNotCommitIfWriterReturnsFalse() {
 cache.put(key, new DiskCache.Writer() {
  @Override
  public boolean write(@NonNull File file) {
   return false;
  }
 });
 assertNull(cache.get(key));
}
origin: bumptech/glide

@VisibleForTesting
synchronized void clearDiskCacheIfCreated() {
 if (diskCache == null) {
  return;
 }
 diskCache.clear();
}
origin: bumptech/glide

cacheFile = helper.getDiskCache().get(originalKey);
if (cacheFile != null) {
 this.sourceKey = sourceId;
origin: bumptech/glide

void encode(DiskCacheProvider diskCacheProvider, Options options) {
 GlideTrace.beginSection("DecodeJob.encode");
 try {
  diskCacheProvider.getDiskCache().put(key,
    new DataCacheWriter<>(encoder, toEncode, options));
 } finally {
  toEncode.unlock();
  GlideTrace.endSection();
 }
}
origin: guolindev/giffun

  public <Z> Resource<Z> load(Key key, ResourceDecoder<File, Z> decoder, int width, int height) {
    File fromCache = diskCache.get(key);
    if (fromCache == null) {
      return null;
    }

    Resource<Z> result = null;
    try {
      result = decoder.decode(fromCache, width, height);
    } catch (IOException e) {
      if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Exception decoding image from cache", e);
      }
    }
    if (result == null) {
      if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Failed to decode image from cache or not present in cache");
      }
      diskCache.delete(key);
    }
    return result;
  }
}
origin: bumptech/glide

public void clearDiskCache() {
 diskCacheProvider.getDiskCache().clear();
}
origin: bumptech/glide

    resourceClass,
    helper.getOptions());
cacheFile = helper.getDiskCache().get(currentKey);
if (cacheFile != null) {
 sourceKey = sourceId;
origin: bumptech/glide

private void cacheData(Object dataToCache) {
 long startTime = LogTime.getLogTime();
 try {
  Encoder<Object> encoder = helper.getSourceEncoder(dataToCache);
  DataCacheWriter<Object> writer =
    new DataCacheWriter<>(encoder, dataToCache, helper.getOptions());
  originalKey = new DataCacheKey(loadData.sourceKey, helper.getSignature());
  helper.getDiskCache().put(originalKey, writer);
  if (Log.isLoggable(TAG, Log.VERBOSE)) {
   Log.v(TAG, "Finished encoding source to cache"
     + ", key: " + originalKey
     + ", data: " + dataToCache
     + ", encoder: " + encoder
     + ", duration: " + LogTime.getElapsedMillis(startTime));
  }
 } finally {
  loadData.fetcher.cleanup();
 }
 sourceCacheGenerator =
   new DataCacheGenerator(Collections.singletonList(loadData.sourceKey), helper, this);
}
origin: guolindev/giffun

private Resource<T> loadFromCache(Key key) throws IOException {
  File cacheFile = diskCacheProvider.getDiskCache().get(key);
  if (cacheFile == null) {
    return null;
  }
  Resource<T> result = null;
  try {
    result = loadProvider.getCacheDecoder().decode(cacheFile, width, height);
  } finally {
    if (result == null) {
      diskCacheProvider.getDiskCache().delete(key);
    }
  }
  return result;
}
origin: bumptech/glide

@Test
public void clearDiskCache_afterOpeningDiskCache_andDeleteDirectoryOutsideGlide_doesNotThrow() {
 DiskCache cache = DiskLruCacheWrapper.create(cacheDir, 1024 * 1024);
 cache.get(mock(Key.class));
 deleteRecursively(cacheDir);
 cache.clear();
}
origin: bumptech/glide

@Test
public void testDoesNotCommitIfWriterWritesButReturnsFalse() {
 cache.put(key, new DiskCache.Writer() {
  @Override
  public boolean write(@NonNull File file) {
   try {
    Util.writeFile(file, data);
   } catch (IOException e) {
    fail(e.toString());
   }
   return false;
  }
 });
 assertNull(cache.get(key));
}
origin: bumptech/glide

@After
public void tearDown() {
 try {
  cache.clear();
 } finally {
  deleteRecursive(dir);
 }
}
origin: bumptech/glide

@Test
public void loadFromCache_afterDiskCacheDeleted_doesNotFail() {
 final DiskCache cache = DiskLruCacheWrapper.create(cacheDir, 1024 * 1024);
 cache.get(mock(Key.class));
 deleteRecursively(cacheDir);
 Glide.init(
   context,
   new GlideBuilder()
     .setDiskCache(new Factory() {
      @Override
      public DiskCache build() {
       return cache;
      }
     }));
 Drawable drawable =
   concurrency.get(Glide.with(context)
     .load(raw.canonical)
     .submit());
 assertThat(drawable).isNotNull();
}
origin: guolindev/giffun

private void writeTransformedToCache(Resource<T> transformed) {
  if (transformed == null || !diskCacheStrategy.cacheResult()) {
    return;
  }
  long startTime = LogTime.getLogTime();
  SourceWriter<Resource<T>> writer = new SourceWriter<Resource<T>>(loadProvider.getEncoder(), transformed);
  diskCacheProvider.getDiskCache().put(resultKey, writer);
  if (Log.isLoggable(TAG, Log.VERBOSE)) {
    logWithTimeAndKey("Wrote transformed from source to cache", startTime);
  }
}
origin: bumptech/glide

 @Test
 public void get_afterDeleteDirectoryOutsideGlideAndClose_doesNotThrow() {
  assumeTrue("A file handle is likely open, so cannot delete dir", !Util.isWindows());
  DiskCache cache = DiskLruCacheWrapper.create(dir, 1024 * 1024);
  cache.get(mock(Key.class));
  deleteRecursive(dir);
  cache.clear();

  cache.get(mock(Key.class));
 }
}
origin: bumptech/glide

@Test
public void testEditIsAbortedIfWriterThrows() throws IOException {
 try {
  cache.put(key, new DiskCache.Writer() {
   @Override
   public boolean write(@NonNull File file) {
    throw new RuntimeException("test");
   }
  });
 } catch (RuntimeException e) {
  // Expected.
 }
 cache.put(key, new DiskCache.Writer() {
  @Override
  public boolean write(@NonNull File file) {
   try {
    Util.writeFile(file, data);
   } catch (IOException e) {
    fail(e.toString());
   }
   return true;
  }
 });
 byte[] received = Util.readFile(cache.get(key), data.length);
 assertArrayEquals(data, received);
}
origin: guolindev/giffun

public void clearDiskCache() {
  diskCacheProvider.getDiskCache().clear();
}
origin: mozilla-tw/Rocket

@Override
public boolean startNext() {
 while (modelLoaders == null || !hasNextModelLoader()) {
  sourceIdIndex++;
  if (sourceIdIndex >= cacheKeys.size()) {
   return false;
  }
  Key sourceId = cacheKeys.get(sourceIdIndex);
  Key originalKey = new DataCacheKey(sourceId, helper.getSignature());
  cacheFile = helper.getDiskCache().get(originalKey);
  if (cacheFile != null) {
   this.sourceKey = sourceId;
   modelLoaders = helper.getModelLoaders(cacheFile);
   modelLoaderIndex = 0;
  }
 }
 loadData = null;
 boolean started = false;
 while (!started && hasNextModelLoader()) {
  ModelLoader<File, ?> modelLoader = modelLoaders.get(modelLoaderIndex++);
  loadData =
    modelLoader.buildLoadData(cacheFile, helper.getWidth(), helper.getHeight(),
      helper.getOptions());
  if (loadData != null && helper.hasLoadPath(loadData.fetcher.getDataClass())) {
   started = true;
   loadData.fetcher.loadData(helper.getPriority(), this);
  }
 }
 return started;
}
origin: guolindev/giffun

private Resource<T> cacheAndDecodeSourceData(A data) throws IOException {
  long startTime = LogTime.getLogTime();
  SourceWriter<A> writer = new SourceWriter<A>(loadProvider.getSourceEncoder(), data);
  diskCacheProvider.getDiskCache().put(resultKey.getOriginalKey(), writer);
  if (Log.isLoggable(TAG, Log.VERBOSE)) {
    logWithTimeAndKey("Wrote source to cache", startTime);
  }
  startTime = LogTime.getLogTime();
  Resource<T> result = loadFromCache(resultKey.getOriginalKey());
  if (Log.isLoggable(TAG, Log.VERBOSE) && result != null) {
    logWithTimeAndKey("Decoded source from cache", startTime);
  }
  return result;
}
com.bumptech.glide.load.engine.cacheDiskCache

Javadoc

An interface for writing to and reading from a disk cache.

Most used methods

  • clear
    Clear the cache.
  • get
    Get the cache for the value at the given key. Note - This is potentially dangerous, someone may writ
  • put
    Write to a key in the cache. Writer is used so that the cache implementation can perform actions aft
  • delete
    Remove the key and value from the cache.

Popular in Java

  • Making http post requests using okhttp
  • addToBackStack (FragmentTransaction)
  • getApplicationContext (Context)
  • setScale (BigDecimal)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now