Skip to content

Commit 3a6bd68

Browse files
committed
"Disc -> Disk" migration. Deleted DiscCacheAware, MemoryCacheAware.
1 parent 303fa22 commit 3a6bd68

10 files changed

+107
-163
lines changed

library/src/com/nostra13/universalimageloader/cache/disc/DiscCacheAware.java

-88
This file was deleted.

library/src/com/nostra13/universalimageloader/cache/disc/DiskCache.java

+61-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,71 @@
1515
*******************************************************************************/
1616
package com.nostra13.universalimageloader.cache.disc;
1717

18+
import android.graphics.Bitmap;
19+
import com.nostra13.universalimageloader.utils.IoUtils;
20+
21+
import java.io.File;
22+
import java.io.IOException;
23+
import java.io.InputStream;
24+
1825
/**
1926
* Interface for disk cache
2027
*
2128
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
2229
* @since 1.9.2
2330
*/
24-
public interface DiskCache extends DiscCacheAware {
31+
public interface DiskCache {
32+
/**
33+
* Returns root directory of disk cache
34+
*
35+
* @return Root directory of disk cache
36+
*/
37+
File getDirectory();
38+
39+
/**
40+
* Returns file of cached image
41+
*
42+
* @param imageUri Original image URI
43+
* @return File of cached image or <b>null</b> if image wasn't cached
44+
*/
45+
File get(String imageUri);
46+
47+
/**
48+
* Saves image stream in disk cache.
49+
* Incoming image stream shouldn't be closed in this method.
50+
*
51+
* @param imageUri Original image URI
52+
* @param imageStream Input stream of image (shouldn't be closed in this method)
53+
* @param listener Listener for saving progress, can be ignored if you don't use
54+
* {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener
55+
* progress listener} in ImageLoader calls
56+
* @return <b>true</b> - if image was saved successfully; <b>false</b> - if image wasn't saved in disk cache.
57+
* @throws java.io.IOException
58+
*/
59+
boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListener listener) throws IOException;
60+
61+
/**
62+
* Saves image bitmap in disk cache.
63+
*
64+
* @param imageUri Original image URI
65+
* @param bitmap Image bitmap
66+
* @return <b>true</b> - if bitmap was saved successfully; <b>false</b> - if bitmap wasn't saved in disk cache.
67+
* @throws IOException
68+
*/
69+
boolean save(String imageUri, Bitmap bitmap) throws IOException;
70+
71+
/**
72+
* Removes image file associated with incoming URI
73+
*
74+
* @param imageUri Image URI
75+
* @return <b>true</b> - if image file is deleted successfully; <b>false</b> - if image file doesn't exist for
76+
* incoming URI or image file can't be deleted.
77+
*/
78+
boolean remove(String imageUri);
79+
80+
/** Closes disk cache, releases resources. */
81+
void close();
82+
83+
/** Clears disk cache. */
84+
void clear();
2585
}

library/src/com/nostra13/universalimageloader/cache/disc/impl/BaseDiscCache.java library/src/com/nostra13/universalimageloader/cache/disc/impl/BaseDiskCache.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @see FileNameGenerator
3636
* @since 1.0.0
3737
*/
38-
public abstract class BaseDiscCache implements DiskCache {
38+
public abstract class BaseDiskCache implements DiskCache {
3939
/** {@value */
4040
public static final int DEFAULT_BUFFER_SIZE = 32 * 1024; // 32 Kb
4141
/** {@value */
@@ -57,15 +57,15 @@ public abstract class BaseDiscCache implements DiskCache {
5757
protected int compressQuality = DEFAULT_COMPRESS_QUALITY;
5858

5959
/** @param cacheDir Directory for file caching */
60-
public BaseDiscCache(File cacheDir) {
60+
public BaseDiskCache(File cacheDir) {
6161
this(cacheDir, null);
6262
}
6363

6464
/**
6565
* @param cacheDir Directory for file caching
6666
* @param reserveCacheDir null-ok; Reserve directory for file caching. It's used when the primary directory isn't available.
6767
*/
68-
public BaseDiscCache(File cacheDir, File reserveCacheDir) {
68+
public BaseDiskCache(File cacheDir, File reserveCacheDir) {
6969
this(cacheDir, reserveCacheDir, DefaultConfigurationFactory.createFileNameGenerator());
7070
}
7171

@@ -75,7 +75,7 @@ public BaseDiscCache(File cacheDir, File reserveCacheDir) {
7575
* @param fileNameGenerator {@linkplain com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator
7676
* Name generator} for cached files
7777
*/
78-
public BaseDiscCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator) {
78+
public BaseDiskCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator) {
7979
if (cacheDir == null) {
8080
throw new IllegalArgumentException("cacheDir" + ERROR_ARG_NULL);
8181
}

library/src/com/nostra13/universalimageloader/cache/disc/impl/LimitedAgeDiscCache.java library/src/com/nostra13/universalimageloader/cache/disc/impl/LimitedAgeDiskCache.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
3434
* @since 1.3.1
3535
*/
36-
public class LimitedAgeDiscCache extends BaseDiscCache {
36+
public class LimitedAgeDiskCache extends BaseDiskCache {
3737

3838
private final long maxFileAge;
3939

@@ -44,7 +44,7 @@ public class LimitedAgeDiscCache extends BaseDiscCache {
4444
* @param maxAge Max file age (in seconds). If file age will exceed this value then it'll be removed on next
4545
* treatment (and therefore be reloaded).
4646
*/
47-
public LimitedAgeDiscCache(File cacheDir, long maxAge) {
47+
public LimitedAgeDiskCache(File cacheDir, long maxAge) {
4848
this(cacheDir, null, DefaultConfigurationFactory.createFileNameGenerator(), maxAge);
4949
}
5050

@@ -53,7 +53,7 @@ public LimitedAgeDiscCache(File cacheDir, long maxAge) {
5353
* @param maxAge Max file age (in seconds). If file age will exceed this value then it'll be removed on next
5454
* treatment (and therefore be reloaded).
5555
*/
56-
public LimitedAgeDiscCache(File cacheDir, File reserveCacheDir, long maxAge) {
56+
public LimitedAgeDiskCache(File cacheDir, File reserveCacheDir, long maxAge) {
5757
this(cacheDir, reserveCacheDir, DefaultConfigurationFactory.createFileNameGenerator(), maxAge);
5858
}
5959

@@ -64,7 +64,7 @@ public LimitedAgeDiscCache(File cacheDir, File reserveCacheDir, long maxAge) {
6464
* @param maxAge Max file age (in seconds). If file age will exceed this value then it'll be removed on next
6565
* treatment (and therefore be reloaded).
6666
*/
67-
public LimitedAgeDiscCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator, long maxAge) {
67+
public LimitedAgeDiskCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator, long maxAge) {
6868
super(cacheDir, reserveCacheDir, fileNameGenerator);
6969
this.maxFileAge = maxAge * 1000; // to milliseconds
7070
}

library/src/com/nostra13/universalimageloader/cache/disc/impl/UnlimitedDiscCache.java library/src/com/nostra13/universalimageloader/cache/disc/impl/UnlimitedDiskCache.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
2727
* @since 1.0.0
2828
*/
29-
public class UnlimitedDiscCache extends BaseDiscCache {
29+
public class UnlimitedDiskCache extends BaseDiskCache {
3030
/** @param cacheDir Directory for file caching */
31-
public UnlimitedDiscCache(File cacheDir) {
31+
public UnlimitedDiskCache(File cacheDir) {
3232
super(cacheDir);
3333
}
3434

3535
/**
3636
* @param cacheDir Directory for file caching
3737
* @param reserveCacheDir null-ok; Reserve directory for file caching. It's used when the primary directory isn't available.
3838
*/
39-
public UnlimitedDiscCache(File cacheDir, File reserveCacheDir) {
39+
public UnlimitedDiskCache(File cacheDir, File reserveCacheDir) {
4040
super(cacheDir, reserveCacheDir);
4141
}
4242

@@ -46,7 +46,7 @@ public UnlimitedDiscCache(File cacheDir, File reserveCacheDir) {
4646
* @param fileNameGenerator {@linkplain com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator
4747
* Name generator} for cached files
4848
*/
49-
public UnlimitedDiscCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator) {
49+
public UnlimitedDiskCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator) {
5050
super(cacheDir, reserveCacheDir, fileNameGenerator);
5151
}
5252
}

library/src/com/nostra13/universalimageloader/cache/disc/impl/ext/LruDiscCache.java library/src/com/nostra13/universalimageloader/cache/disc/impl/ext/LruDiskCache.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @see FileNameGenerator
3737
* @since 1.9.2
3838
*/
39-
public class LruDiscCache implements DiskCache {
39+
public class LruDiskCache implements DiskCache {
4040
/** {@value */
4141
public static final int DEFAULT_BUFFER_SIZE = 32 * 1024; // 32 Kb
4242
/** {@value */
@@ -65,7 +65,7 @@ public class LruDiscCache implements DiskCache {
6565
* @param cacheMaxSize Max cache size in bytes. <b>0</b> means cache size is unlimited.
6666
* @throws IOException if cache can't be initialized (e.g. "No space left on device")
6767
*/
68-
public LruDiscCache(File cacheDir, FileNameGenerator fileNameGenerator, long cacheMaxSize) throws IOException {
68+
public LruDiskCache(File cacheDir, FileNameGenerator fileNameGenerator, long cacheMaxSize) throws IOException {
6969
this(cacheDir, null, fileNameGenerator, cacheMaxSize, 0);
7070
}
7171

@@ -79,7 +79,7 @@ public LruDiscCache(File cacheDir, FileNameGenerator fileNameGenerator, long cac
7979
* @param cacheMaxFileCount Max file count in cache. <b>0</b> means file count is unlimited.
8080
* @throws IOException if cache can't be initialized (e.g. "No space left on device")
8181
*/
82-
public LruDiscCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator, long cacheMaxSize,
82+
public LruDiskCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator, long cacheMaxSize,
8383
int cacheMaxFileCount) throws IOException {
8484
if (cacheDir == null) {
8585
throw new IllegalArgumentException("cacheDir" + ERROR_ARG_NULL);

library/src/com/nostra13/universalimageloader/cache/memory/MemoryCache.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,32 @@
1717

1818
import android.graphics.Bitmap;
1919

20+
import java.util.Collection;
21+
2022
/**
2123
* Interface for memory cache
2224
*
2325
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
2426
* @since 1.9.2
2527
*/
26-
public interface MemoryCache extends MemoryCacheAware<String, Bitmap> {
28+
public interface MemoryCache {
29+
/**
30+
* Puts value into cache by key
31+
*
32+
* @return <b>true</b> - if value was put into cache successfully, <b>false</b> - if value was <b>not</b> put into
33+
* cache
34+
*/
35+
boolean put(String key, Bitmap value);
36+
37+
/** Returns value by key. If there is no value for key then null will be returned. */
38+
Bitmap get(String key);
39+
40+
/** Removes item by key */
41+
Bitmap remove(String key);
42+
43+
/** Returns all keys of cache */
44+
Collection<String> keys();
45+
46+
/** Remove all items from cache */
47+
void clear();
2748
}

library/src/com/nostra13/universalimageloader/cache/memory/MemoryCacheAware.java

-49
This file was deleted.

0 commit comments

Comments
 (0)