19fc12334a7d14347cd6951d0653264b2597bd3a0Sam Juddpackage com.bumptech.glide.load.engine.cache; 2f7de145d9bebfdd354a234479e1d1f28e1d3e11bSam Judd 39fc12334a7d14347cd6951d0653264b2597bd3a0Sam Juddimport com.bumptech.glide.load.Key; 47bead36a3031afd9ffb74f06d254f4b11836ceffSam Judd 5309fea9a2ecf04b8466cc3869b5af798199cd8d5Sam Juddimport java.io.InputStream; 6309fea9a2ecf04b8466cc3869b5af798199cd8d5Sam Juddimport java.io.OutputStream; 7309fea9a2ecf04b8466cc3869b5af798199cd8d5Sam Judd 8f7de145d9bebfdd354a234479e1d1f28e1d3e11bSam Judd/** 9d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * An interface for writing to and reading from a disk cache 10f7de145d9bebfdd354a234479e1d1f28e1d3e11bSam Judd */ 11f7de145d9bebfdd354a234479e1d1f28e1d3e11bSam Juddpublic interface DiskCache { 12d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd /** 13d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * An interface to actually write data to a key in 14d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * the disk cache 15d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd */ 16309fea9a2ecf04b8466cc3869b5af798199cd8d5Sam Judd public interface Writer { 1780b7691daac313059e4311214249fa6da53451edSam Judd /** 1880b7691daac313059e4311214249fa6da53451edSam Judd * Writes data to the output stream and returns true if the write was successful and should be committed, and 1980b7691daac313059e4311214249fa6da53451edSam Judd * false if the write should be aborted. 2080b7691daac313059e4311214249fa6da53451edSam Judd * 2180b7691daac313059e4311214249fa6da53451edSam Judd * @param os The output stream the Writer should write to. 2280b7691daac313059e4311214249fa6da53451edSam Judd */ 2380b7691daac313059e4311214249fa6da53451edSam Judd public boolean write(OutputStream os); 24309fea9a2ecf04b8466cc3869b5af798199cd8d5Sam Judd } 25309fea9a2ecf04b8466cc3869b5af798199cd8d5Sam Judd 26d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd /** 27d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * Get an InputStream for the value at the given key. 28d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * 29d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * @param key The key in the cache 30d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * @return An InputStream representing the data at key at the time get is called 31d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd */ 327bead36a3031afd9ffb74f06d254f4b11836ceffSam Judd public InputStream get(Key key); 33d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd 34d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd /** 35d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * Write to a key in the cache. {@link Writer} is used so that the cache implementation 36d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * can perform actions after the write finishes, like commit (via atomic file rename). 37d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * 38d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * @param key The key to write to 39d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * @param writer An interface that will write data given an OutputStream for the key 40d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd */ 417bead36a3031afd9ffb74f06d254f4b11836ceffSam Judd public void put(Key key, Writer writer); 42d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd 43d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd /** 44d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * Remove the key and value from the cache 45d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * 46d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd * @param key The key to remove 47d66ef49022858664841d3d60d0d531bdd13bd882Sam Judd */ 487bead36a3031afd9ffb74f06d254f4b11836ceffSam Judd public void delete(Key key); 49f7de145d9bebfdd354a234479e1d1f28e1d3e11bSam Judd} 50