aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-07-21 12:21:01 -0700
committerScott Jackson <daneren2005@gmail.com>2013-07-21 12:21:01 -0700
commita1c809804609f30f7662adbda94aee1988014cab (patch)
tree01e3e917edfaa1d10c5b31e9aafd41c9594ab9f7
parent8dbb7aa01530b55a4a0b751b22098585578c5838 (diff)
downloaddsub-a1c809804609f30f7662adbda94aee1988014cab.tar.gz
dsub-a1c809804609f30f7662adbda94aee1988014cab.tar.bz2
dsub-a1c809804609f30f7662adbda94aee1988014cab.zip
Remove custom LRUCache, use standard
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java12
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/LRUCache.java102
3 files changed, 7 insertions, 111 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java
index e9ee9bab..943b5eb2 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -25,6 +25,7 @@ import org.apache.http.HttpResponse;
import android.content.Context;
import android.graphics.Bitmap;
+import android.support.v4.util.LruCache;
import github.daneren2005.dsub.domain.ChatMessage;
import github.daneren2005.dsub.domain.Genre;
import github.daneren2005.dsub.domain.Indexes;
@@ -34,14 +35,11 @@ import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.MusicFolder;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.domain.PodcastChannel;
-import github.daneren2005.dsub.domain.PodcastEpisode;
import github.daneren2005.dsub.domain.SearchCritera;
import github.daneren2005.dsub.domain.SearchResult;
import github.daneren2005.dsub.domain.Share;
import github.daneren2005.dsub.domain.Version;
import github.daneren2005.dsub.util.CancellableTask;
-import github.daneren2005.dsub.util.FileUtil;
-import github.daneren2005.dsub.util.LRUCache;
import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.util.TimeLimitedCache;
import github.daneren2005.dsub.util.Util;
@@ -55,7 +53,7 @@ public class CachedMusicService implements MusicService {
private static final int TTL_MUSIC_DIR = 5 * 60; // Five minutes
private final MusicService musicService;
- private final LRUCache<String, TimeLimitedCache<MusicDirectory>> cachedMusicDirectories;
+ private final LruCache<String, TimeLimitedCache<MusicDirectory>> cachedMusicDirectories;
private final TimeLimitedCache<Boolean> cachedLicenseValid = new TimeLimitedCache<Boolean>(120, TimeUnit.SECONDS);
private final TimeLimitedCache<Indexes> cachedIndexes = new TimeLimitedCache<Indexes>(60 * 60, TimeUnit.SECONDS);
private final TimeLimitedCache<List<Playlist>> cachedPlaylists = new TimeLimitedCache<List<Playlist>>(3600, TimeUnit.SECONDS);
@@ -66,7 +64,7 @@ public class CachedMusicService implements MusicService {
public CachedMusicService(MusicService musicService) {
this.musicService = musicService;
- cachedMusicDirectories = new LRUCache<String, TimeLimitedCache<MusicDirectory>>(MUSIC_DIR_CACHE_SIZE);
+ cachedMusicDirectories = new LruCache<String, TimeLimitedCache<MusicDirectory>>(MUSIC_DIR_CACHE_SIZE);
}
@Override
@@ -106,7 +104,7 @@ public class CachedMusicService implements MusicService {
if (refresh) {
cachedIndexes.clear();
cachedMusicFolders.clear();
- cachedMusicDirectories.clear();
+ cachedMusicDirectories.evictAll();
}
Indexes result = cachedIndexes.get();
if (result == null) {
@@ -364,7 +362,7 @@ public class CachedMusicService implements MusicService {
String newUrl = Util.getRestUrl(context, null);
if (!Util.equals(newUrl, restUrl)) {
cachedMusicFolders.clear();
- cachedMusicDirectories.clear();
+ cachedMusicDirectories.evictAll();
cachedLicenseValid.clear();
cachedIndexes.clear();
cachedPlaylists.clear();
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index e8803ad4..04875f34 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -34,7 +34,6 @@ import github.daneren2005.dsub.domain.RepeatMode;
import github.daneren2005.dsub.receiver.MediaButtonIntentReceiver;
import github.daneren2005.dsub.util.CancellableTask;
import github.daneren2005.dsub.util.Constants;
-import github.daneren2005.dsub.util.LRUCache;
import github.daneren2005.dsub.util.ShufflePlayBuffer;
import github.daneren2005.dsub.util.SimpleServiceBinder;
import github.daneren2005.dsub.util.Util;
@@ -62,6 +61,7 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.PowerManager;
import android.util.Log;
+import android.support.v4.util.LruCache;
import java.net.URLEncoder;
/**
@@ -95,7 +95,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private final DownloadServiceLifecycleSupport lifecycleSupport = new DownloadServiceLifecycleSupport(this);
private final ShufflePlayBuffer shufflePlayBuffer = new ShufflePlayBuffer(this);
- private final LRUCache<MusicDirectory.Entry, DownloadFile> downloadFileCache = new LRUCache<MusicDirectory.Entry, DownloadFile>(100);
+ private final LruCache<MusicDirectory.Entry, DownloadFile> downloadFileCache = new LruCache<MusicDirectory.Entry, DownloadFile>(100);
private final List<DownloadFile> cleanupCandidates = new ArrayList<DownloadFile>();
private final Scrobbler scrobbler = new Scrobbler();
private final JukeboxService jukeboxService = new JukeboxService(this);
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/LRUCache.java b/subsonic-android/src/github/daneren2005/dsub/util/LRUCache.java
deleted file mode 100644
index 9b12a204..00000000
--- a/subsonic-android/src/github/daneren2005/dsub/util/LRUCache.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- This file is part of Subsonic.
-
- Subsonic is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Subsonic is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
-
- Copyright 2009 (C) Sindre Mehus
- */
-package github.daneren2005.dsub.util;
-
-import java.lang.ref.SoftReference;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Sindre Mehus
- */
-public class LRUCache<K,V>{
-
- private final int capacity;
- private final Map<K, TimestampedValue> map;
-
- public LRUCache(int capacity) {
- map = new HashMap<K, TimestampedValue>(capacity);
- this.capacity = capacity;
- }
-
- public synchronized V get(K key) {
- TimestampedValue value = map.get(key);
-
- V result = null;
- if (value != null) {
- value.updateTimestamp();
- result = value.getValue();
- }
-
- return result;
- }
-
- public synchronized void put(K key, V value) {
- if (map.size() >= capacity) {
- removeOldest();
- }
- map.put(key, new TimestampedValue(value));
- }
-
- public void clear() {
- map.clear();
- }
-
- private void removeOldest() {
- K oldestKey = null;
- long oldestTimestamp = Long.MAX_VALUE;
-
- for (Map.Entry<K, TimestampedValue> entry : map.entrySet()) {
- K key = entry.getKey();
- TimestampedValue value = entry.getValue();
- if (value.getTimestamp() < oldestTimestamp) {
- oldestTimestamp = value.getTimestamp();
- oldestKey = key;
- }
- }
-
- if (oldestKey != null) {
- map.remove(oldestKey);
- }
- }
-
- private final class TimestampedValue {
-
- private final SoftReference<V> value;
- private long timestamp;
-
- public TimestampedValue(V value) {
- this.value = new SoftReference<V>(value);
- updateTimestamp();
- }
-
- public V getValue() {
- return value.get();
- }
-
- public long getTimestamp() {
- return timestamp;
- }
-
- public void updateTimestamp() {
- timestamp = System.currentTimeMillis();
- }
- }
-
-} \ No newline at end of file