Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for diskless cache -- just pass null as the cache root

  • Loading branch information...
commit 69b37a326f150575a668119b59f01cb82c40e0be 1 parent 5058118
@commonsguy authored
View
BIN  libs/CWAC-Bus.jar
Binary file not shown
View
4 src/com/commonsware/cwac/cache/AsyncCache.java
@@ -48,7 +48,9 @@ public AsyncCache(File cacheRoot, B bus, DiskCachePolicy policy,
this.bus=bus;
this.maxSize=maxSize;
- new CacheCleanTask().execute(policy);
+ if (cacheRoot!=null) {
+ new CacheCleanTask().execute(policy);
+ }
}
public V get(K key, M message) {
View
37 src/com/commonsware/cwac/cache/WebImageCache.java
@@ -116,7 +116,7 @@ public void run() {
public int getStatus(String key) {
int result=super.getStatus(key);
- if (result==CACHE_NONE) {
+ if (result==CACHE_NONE && getCacheRoot()!=null) {
try {
File cache=buildCachedImagePath(key);
@@ -134,18 +134,23 @@ public int getStatus(String key) {
protected Drawable create(String key, Bundle message,
int forceStyle) {
- try {
- File cache=buildCachedImagePath(key);
-
- if (cache.exists() && forceStyle==FORCE_NONE) {
- return(new BitmapDrawable(cache.getAbsolutePath()));
+ if (getCacheRoot()!=null) {
+ try {
+ File cache=buildCachedImagePath(key);
+
+ if (cache.exists() && forceStyle==FORCE_NONE) {
+ return(new BitmapDrawable(cache.getAbsolutePath()));
+ }
+ else {
+ new FetchImageTask().execute(message, key, cache);
+ }
}
- else {
- new FetchImageTask().execute(message, key, cache);
+ catch (Throwable t) {
+ Log.e(TAG, "Exception loading image", t);
}
}
- catch (Throwable t) {
- Log.e(TAG, "Exception loading image", t);
+ else {
+ new FetchImageTask().execute(message, key, null);
}
return(placeholder);
@@ -188,11 +193,13 @@ protected Void doInBackground(Object... params) {
getBus().send(message);
}
- FileOutputStream file=new FileOutputStream(cache);
-
- file.write(raw);
- file.flush();
- file.close();
+ if (cache!=null) {
+ FileOutputStream file=new FileOutputStream(cache);
+
+ file.write(raw);
+ file.flush();
+ file.close();
+ }
}
catch (Throwable t) {
Log.e(TAG, "Exception downloading image", t);
Please sign in to comment.
Something went wrong with that request. Please try again.