• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.bumptech.glide.load.engine.cache;
2 
3 import com.bumptech.glide.load.Key;
4 
5 import java.io.File;
6 
7 /**
8  * An interface for writing to and reading from a disk cache.
9  */
10 public interface DiskCache {
11     /**
12      * An interface to actually write data to a key in the disk cache.
13      */
14     interface Writer {
15         /**
16          * Writes data to the file and returns true if the write was successful and should be committed, and
17          * false if the write should be aborted.
18          *
19          * @param file The File the Writer should write to.
20          */
write(File file)21         boolean write(File file);
22     }
23 
24     /**
25      * Get the cache for the value at the given key.
26      *
27      * <p>
28      *     Note - This is potentially dangerous, someone may write a new value to the file at any point in timeand we
29      *     won't know about it.
30      * </p>
31      *
32      * @param key The key in the cache.
33      * @return An InputStream representing the data at key at the time get is called.
34      */
get(Key key)35     File get(Key key);
36 
37     /**
38      * Write to a key in the cache. {@link Writer} is used so that the cache implementation can perform actions after
39      * the write finishes, like commit (via atomic file rename).
40      *
41      * @param key The key to write to.
42      * @param writer An interface that will write data given an OutputStream for the key.
43      */
put(Key key, Writer writer)44     void put(Key key, Writer writer);
45 
46     /**
47      * Remove the key and value from the cache.
48      *
49      * @param key The key to remove.
50      */
delete(Key key)51     void delete(Key key);
52 }
53