aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/java/com/bumptech/glide/load/engine/cache/DiskCache.java
blob: 81e6360eee883785eadea03618b32405605f990f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.bumptech.glide.load.engine.cache;

import com.bumptech.glide.load.Key;

import java.io.File;

/**
 * An interface for writing to and reading from a disk cache
 */
public interface DiskCache {
    /**
     * An interface to actually write data to a key in
     * the disk cache
     */
    public interface Writer {
        /**
         * Writes data to the file and returns true if the write was successful and should be committed, and
         * false if the write should be aborted.
         *
         * @param file The File the Writer should write to.
         */
        public boolean write(File file);
    }

    /**
     * Get the cache for the value at the given key.
     *
     * <p>
     *     Note - This is potentially dangerous, someone may write a new value to the file at any point in time
     *     and we won't know about it.
     * </p>
     *
     * @param key The key in the cache
     * @return An InputStream representing the data at key at the time get is called
     */
    public File get(Key key);

    /**
     * Write to a key in the cache. {@link Writer} is used so that the cache implementation
     * can perform actions after the write finishes, like commit (via atomic file rename).
     *
     * @param key The key to write to
     * @param writer An interface that will write data given an OutputStream for the key
     */
    public void put(Key key, Writer writer);

    /**
     * Remove the key and value from the cache
     *
     * @param key The key to remove
     */
    public void delete(Key key);
}