diff options
author | Jesse Wilson <jessewilson@google.com> | 2011-02-10 11:33:19 -0800 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2011-02-22 08:42:11 -0800 |
commit | 0c7faeee47e7629f2d23a2e3b25bc4f121252080 (patch) | |
tree | fd0ba89fb2ddcc204bb3f42a739bde96f267a2ac /packages/SettingsProvider | |
parent | 83a7b963f0070022d98853ea1fb4fa5c81cc5e79 (diff) | |
download | frameworks_base-0c7faeee47e7629f2d23a2e3b25bc4f121252080.zip frameworks_base-0c7faeee47e7629f2d23a2e3b25bc4f121252080.tar.gz frameworks_base-0c7faeee47e7629f2d23a2e3b25bc4f121252080.tar.bz2 |
Adopt LruCache in SettingsProvider.
Change-Id: I223ed2a4bd90234ea7e3447f19e18c68beae2763
http://b/3184897
Diffstat (limited to 'packages/SettingsProvider')
-rw-r--r-- | packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java index f8809d7..9017ca3 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java @@ -17,11 +17,7 @@ package com.android.providers.settings; import java.io.FileNotFoundException; -import java.io.UnsupportedEncodingException; -import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; -import java.util.LinkedHashMap; -import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -47,6 +43,7 @@ import android.provider.MediaStore; import android.provider.Settings; import android.text.TextUtils; import android.util.Log; +import android.util.LruCache; public class SettingsProvider extends ContentProvider { private static final String TAG = "SettingsProvider"; @@ -293,7 +290,7 @@ public class SettingsProvider extends ContentProvider { "" + (MAX_CACHE_ENTRIES + 1) /* limit */); try { synchronized (cache) { - cache.clear(); + cache.evictAll(); cache.setFullyMatchesDisk(true); // optimistic int rows = 0; while (c.moveToNext()) { @@ -359,8 +356,8 @@ public class SettingsProvider extends ContentProvider { // possibly with a null value, or null on failure. private Bundle lookupValue(String table, SettingsCache cache, String key) { synchronized (cache) { - if (cache.containsKey(key)) { - Bundle value = cache.get(key); + Bundle value = cache.get(key); + if (value != null) { if (value != TOO_LARGE_TO_CACHE_MARKER) { return value; } @@ -725,13 +722,13 @@ public class SettingsProvider extends ContentProvider { * associated helper functions to keep cache coherent with the * database. */ - private static final class SettingsCache extends LinkedHashMap<String, Bundle> { + private static final class SettingsCache extends LruCache<String, Bundle> { private final String mCacheName; private boolean mCacheFullyMatchesDisk = false; // has the whole database slurped. public SettingsCache(String name) { - super(MAX_CACHE_ENTRIES, 0.75f /* load factor */, true /* access ordered */); + super(MAX_CACHE_ENTRIES); mCacheName = name; } @@ -751,14 +748,8 @@ public class SettingsProvider extends ContentProvider { } @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - if (size() <= MAX_CACHE_ENTRIES) { - return false; - } - synchronized (this) { - mCacheFullyMatchesDisk = false; - } - return true; + protected synchronized void entryEvicted(String key, Bundle value) { + mCacheFullyMatchesDisk = false; } /** @@ -772,7 +763,7 @@ public class SettingsProvider extends ContentProvider { Bundle bundle = (value == null) ? NULL_SETTING : Bundle.forPair("value", value); if (value == null || value.length() <= MAX_CACHE_ENTRY_SIZE) { synchronized (this) { - if (!containsKey(key)) { + if (get(key) == null) { put(key, bundle); } } @@ -826,7 +817,7 @@ public class SettingsProvider extends ContentProvider { return; } synchronized (cache) { - cache.clear(); + cache.evictAll(); cache.mCacheFullyMatchesDisk = false; } } |