aboutsummaryrefslogtreecommitdiff
path: root/src/github
diff options
context:
space:
mode:
authordaneren2005 <daneren2005@gmail.com>2013-09-23 17:28:23 -0700
committerdaneren2005 <daneren2005@gmail.com>2013-09-23 17:28:23 -0700
commitb846490066d9643cf78ed2afabebb3da275670a4 (patch)
treefc5f1b23d06d51322fe7bad8f1db0ca95210e679 /src/github
parentc6e49fa348769e0e971434674618b929543c7520 (diff)
downloaddsub-b846490066d9643cf78ed2afabebb3da275670a4.tar.gz
dsub-b846490066d9643cf78ed2afabebb3da275670a4.tar.bz2
dsub-b846490066d9643cf78ed2afabebb3da275670a4.zip
#159: First stab at caching structure using serialization
Diffstat (limited to 'src/github')
-rw-r--r--src/github/daneren2005/dsub/service/CachedMusicService.java15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java
index cc8d2dbd..767bb87c 100644
--- a/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -42,6 +42,7 @@ import github.daneren2005.dsub.domain.Version;
import github.daneren2005.dsub.util.CancellableTask;
import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.util.TimeLimitedCache;
+import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.Util;
/**
@@ -120,10 +121,19 @@ public class CachedMusicService implements MusicService {
TimeLimitedCache<MusicDirectory> cache = refresh ? null : cachedMusicDirectories.get(id);
MusicDirectory dir = cache == null ? null : cache.get();
if (dir == null) {
+ if(!refresh) {
+ dir = FileUtil.deserialize(context, getCacheName(context, "directory", id), MusicDirectory.class);
+
+ if(dir != null) {
+ return dir;
+ }
+ }
+
dir = musicService.getMusicDirectory(id, name, refresh, context, progressListener);
cache = new TimeLimitedCache<MusicDirectory>(TTL_MUSIC_DIR, TimeUnit.SECONDS);
cache.set(dir);
cachedMusicDirectories.put(id, cache);
+ FileUtil.serialize(context, dir, getCacheName(context, "directory", id));
}
return dir;
}
@@ -356,7 +366,10 @@ public class CachedMusicService implements MusicService {
return musicService.processOfflineSyncs(context, progressListener);
}
-
+ private void getCacheName(Context context, String name, String id) {
+ String s = Util.getRestUrl(context, null) + id;
+ return name + "-" + s.hashCode() + ".ser";
+ }
private void checkSettingsChanged(Context context) {
String newUrl = Util.getRestUrl(context, null);