Skip to content

Commit 5d2ce1c

Browse files
committed
Introduced DiskCache and MemoryCache interfaces instead of deprecated DiscCacheAware and MemoryCacheAware.
Preparing for global renaming "disc" -> "disk". Renamed in java docs and variables, deprecated "disc" API.
1 parent e27687d commit 5d2ce1c

29 files changed

+359
-224
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
*
2828
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
2929
* @since 1.0.0
30+
* @deprecated Use {@link DiskCache DiskCache} instead
3031
*/
32+
@Deprecated
3133
public interface DiscCacheAware {
3234

3335
/**
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*******************************************************************************
2+
* Copyright 2014 Sergey Tarasevich
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
package com.nostra13.universalimageloader.cache.disc;
17+
18+
/**
19+
* Interface for disk cache
20+
*
21+
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
22+
* @since 1.9.2
23+
*/
24+
public interface DiskCache extends DiscCacheAware {
25+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package com.nostra13.universalimageloader.cache.disc.impl;
1717

1818
import android.graphics.Bitmap;
19-
import com.nostra13.universalimageloader.cache.disc.DiscCacheAware;
19+
import com.nostra13.universalimageloader.cache.disc.DiskCache;
2020
import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
2121
import com.nostra13.universalimageloader.core.DefaultConfigurationFactory;
2222
import com.nostra13.universalimageloader.utils.IoUtils;
@@ -29,13 +29,13 @@
2929
import java.io.OutputStream;
3030

3131
/**
32-
* Base disc cache.
32+
* Base disk cache.
3333
*
3434
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
3535
* @see FileNameGenerator
3636
* @since 1.0.0
3737
*/
38-
public abstract class BaseDiscCache implements DiscCacheAware {
38+
public abstract class BaseDiscCache implements DiskCache {
3939
/** {@value */
4040
public static final int DEFAULT_BUFFER_SIZE = 32 * 1024; // 32 Kb
4141
/** {@value */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.io.File;
2121

2222
/**
23-
* Default implementation of {@linkplain com.nostra13.universalimageloader.cache.disc.DiscCacheAware disc cache}.
23+
* Default implementation of {@linkplain com.nostra13.universalimageloader.cache.disc.DiskCache disk cache}.
2424
* Cache size is unlimited.
2525
*
2626
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package com.nostra13.universalimageloader.cache.disc.impl.ext;
1717

1818
import android.graphics.Bitmap;
19-
import com.nostra13.universalimageloader.cache.disc.DiscCacheAware;
19+
import com.nostra13.universalimageloader.cache.disc.DiskCache;
2020
import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
2121
import com.nostra13.universalimageloader.utils.IoUtils;
2222
import com.nostra13.universalimageloader.utils.L;
@@ -28,15 +28,15 @@
2828
import java.io.OutputStream;
2929

3030
/**
31-
* Disc cache based on "Least-Recently Used" principle. Adapter pattern, adapts
31+
* Disk cache based on "Least-Recently Used" principle. Adapter pattern, adapts
3232
* {@link com.nostra13.universalimageloader.cache.disc.impl.ext.DiskLruCache DiskLruCache} to
33-
* {@link com.nostra13.universalimageloader.cache.disc.DiscCacheAware DiscCacheAware}
33+
* {@link com.nostra13.universalimageloader.cache.disc.DiskCache DiskCache}
3434
*
3535
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
3636
* @see FileNameGenerator
3737
* @since 1.9.2
3838
*/
39-
public class LruDiscCache implements DiscCacheAware {
39+
public class LruDiscCache implements DiskCache {
4040
/** {@value */
4141
public static final int DEFAULT_BUFFER_SIZE = 32 * 1024; // 32 Kb
4242
/** {@value */

library/src/com/nostra13/universalimageloader/cache/disc/naming/FileNameGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package com.nostra13.universalimageloader.cache.disc.naming;
1717

1818
/**
19-
* Generates names for files at disc cache
19+
* Generates names for files at disk cache
2020
*
2121
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
2222
* @since 1.3.1

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*******************************************************************************/
1616
package com.nostra13.universalimageloader.cache.memory;
1717

18+
import android.graphics.Bitmap;
19+
1820
import java.lang.ref.Reference;
1921
import java.util.*;
2022

@@ -25,36 +27,36 @@
2527
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
2628
* @since 1.0.0
2729
*/
28-
public abstract class BaseMemoryCache<K, V> implements MemoryCacheAware<K, V> {
30+
public abstract class BaseMemoryCache implements MemoryCache {
2931

3032
/** Stores not strong references to objects */
31-
private final Map<K, Reference<V>> softMap = Collections.synchronizedMap(new HashMap<K, Reference<V>>());
33+
private final Map<String, Reference<Bitmap>> softMap = Collections.synchronizedMap(new HashMap<String, Reference<Bitmap>>());
3234

3335
@Override
34-
public V get(K key) {
35-
V result = null;
36-
Reference<V> reference = softMap.get(key);
36+
public Bitmap get(String key) {
37+
Bitmap result = null;
38+
Reference<Bitmap> reference = softMap.get(key);
3739
if (reference != null) {
3840
result = reference.get();
3941
}
4042
return result;
4143
}
4244

4345
@Override
44-
public boolean put(K key, V value) {
46+
public boolean put(String key, Bitmap value) {
4547
softMap.put(key, createReference(value));
4648
return true;
4749
}
4850

4951
@Override
50-
public void remove(K key) {
52+
public void remove(String key) {
5153
softMap.remove(key);
5254
}
5355

5456
@Override
55-
public Collection<K> keys() {
57+
public Collection<String> keys() {
5658
synchronized (softMap) {
57-
return new HashSet<K>(softMap.keySet());
59+
return new HashSet<String>(softMap.keySet());
5860
}
5961
}
6062

@@ -64,5 +66,5 @@ public void clear() {
6466
}
6567

6668
/** Creates {@linkplain Reference not strong} reference of value */
67-
protected abstract Reference<V> createReference(V value);
69+
protected abstract Reference<Bitmap> createReference(Bitmap value);
6870
}

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*******************************************************************************/
1616
package com.nostra13.universalimageloader.cache.memory;
1717

18+
import android.graphics.Bitmap;
19+
1820
import com.nostra13.universalimageloader.utils.L;
1921

2022
import java.util.Collections;
@@ -33,7 +35,7 @@
3335
* @see BaseMemoryCache
3436
* @since 1.0.0
3537
*/
36-
public abstract class LimitedMemoryCache<K, V> extends BaseMemoryCache<K, V> {
38+
public abstract class LimitedMemoryCache extends BaseMemoryCache {
3739

3840
private static final int MAX_NORMAL_CACHE_SIZE_IN_MB = 16;
3941
private static final int MAX_NORMAL_CACHE_SIZE = MAX_NORMAL_CACHE_SIZE_IN_MB * 1024 * 1024;
@@ -47,7 +49,7 @@ public abstract class LimitedMemoryCache<K, V> extends BaseMemoryCache<K, V> {
4749
* limit then first object is deleted (but it continue exist at {@link #softMap} and can be collected by GC at any
4850
* time)
4951
*/
50-
private final List<V> hardCache = Collections.synchronizedList(new LinkedList<V>());
52+
private final List<Bitmap> hardCache = Collections.synchronizedList(new LinkedList<Bitmap>());
5153

5254
/** @param sizeLimit Maximum size for cache (in bytes) */
5355
public LimitedMemoryCache(int sizeLimit) {
@@ -59,15 +61,15 @@ public LimitedMemoryCache(int sizeLimit) {
5961
}
6062

6163
@Override
62-
public boolean put(K key, V value) {
64+
public boolean put(String key, Bitmap value) {
6365
boolean putSuccessfully = false;
6466
// Try to add value to hard cache
6567
int valueSize = getSize(value);
6668
int sizeLimit = getSizeLimit();
6769
int curCacheSize = cacheSize.get();
6870
if (valueSize < sizeLimit) {
6971
while (curCacheSize + valueSize > sizeLimit) {
70-
V removedValue = removeNext();
72+
Bitmap removedValue = removeNext();
7173
if (hardCache.remove(removedValue)) {
7274
curCacheSize = cacheSize.addAndGet(-getSize(removedValue));
7375
}
@@ -83,8 +85,8 @@ public boolean put(K key, V value) {
8385
}
8486

8587
@Override
86-
public void remove(K key) {
87-
V value = super.get(key);
88+
public void remove(String key) {
89+
Bitmap value = super.get(key);
8890
if (value != null) {
8991
if (hardCache.remove(value)) {
9092
cacheSize.addAndGet(-getSize(value));
@@ -104,7 +106,7 @@ protected int getSizeLimit() {
104106
return sizeLimit;
105107
}
106108

107-
protected abstract int getSize(V value);
109+
protected abstract int getSize(Bitmap value);
108110

109-
protected abstract V removeNext();
111+
protected abstract Bitmap removeNext();
110112
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************************
2+
* Copyright 2014 Sergey Tarasevich
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
package com.nostra13.universalimageloader.cache.memory;
17+
18+
import android.graphics.Bitmap;
19+
20+
/**
21+
* Interface for memory cache
22+
*
23+
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
24+
* @since 1.9.2
25+
*/
26+
public interface MemoryCache extends MemoryCacheAware<String, Bitmap> {
27+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
*
2323
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
2424
* @since 1.0.0
25+
* @deprecated Use {@link com.nostra13.universalimageloader.cache.memory.MemoryCache MemoryCache}
26+
* instead
2527
*/
28+
@Deprecated
2629
public interface MemoryCacheAware<K, V> {
2730
/**
2831
* Puts value into cache by key

library/src/com/nostra13/universalimageloader/cache/memory/impl/FIFOLimitedMemoryCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
3535
* @since 1.0.0
3636
*/
37-
public class FIFOLimitedMemoryCache extends LimitedMemoryCache<String, Bitmap> {
37+
public class FIFOLimitedMemoryCache extends LimitedMemoryCache {
3838

3939
private final List<Bitmap> queue = Collections.synchronizedList(new LinkedList<Bitmap>());
4040

library/src/com/nostra13/universalimageloader/cache/memory/impl/FuzzyKeyMemoryCache.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,38 @@
1515
*******************************************************************************/
1616
package com.nostra13.universalimageloader.cache.memory.impl;
1717

18-
import com.nostra13.universalimageloader.cache.memory.MemoryCacheAware;
18+
import android.graphics.Bitmap;
19+
20+
import com.nostra13.universalimageloader.cache.memory.MemoryCache;
1921

2022
import java.util.Collection;
2123
import java.util.Comparator;
2224

2325
/**
24-
* Decorator for {@link MemoryCacheAware}. Provides special feature for cache: some different keys are considered as
26+
* Decorator for {@link MemoryCache}. Provides special feature for cache: some different keys are considered as
2527
* equals (using {@link Comparator comparator}). And when you try to put some value into cache by key so entries with
2628
* "equals" keys will be removed from cache before.<br />
2729
* <b>NOTE:</b> Used for internal needs. Normally you don't need to use this class.
2830
*
2931
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
3032
* @since 1.0.0
3133
*/
32-
public class FuzzyKeyMemoryCache<K, V> implements MemoryCacheAware<K, V> {
34+
public class FuzzyKeyMemoryCache implements MemoryCache {
3335

34-
private final MemoryCacheAware<K, V> cache;
35-
private final Comparator<K> keyComparator;
36+
private final MemoryCache cache;
37+
private final Comparator<String> keyComparator;
3638

37-
public FuzzyKeyMemoryCache(MemoryCacheAware<K, V> cache, Comparator<K> keyComparator) {
39+
public FuzzyKeyMemoryCache(MemoryCache cache, Comparator<String> keyComparator) {
3840
this.cache = cache;
3941
this.keyComparator = keyComparator;
4042
}
4143

4244
@Override
43-
public boolean put(K key, V value) {
45+
public boolean put(String key, Bitmap value) {
4446
// Search equal key and remove this entry
4547
synchronized (cache) {
46-
K keyToRemove = null;
47-
for (K cacheKey : cache.keys()) {
48+
String keyToRemove = null;
49+
for (String cacheKey : cache.keys()) {
4850
if (keyComparator.compare(key, cacheKey) == 0) {
4951
keyToRemove = cacheKey;
5052
break;
@@ -58,12 +60,12 @@ public boolean put(K key, V value) {
5860
}
5961

6062
@Override
61-
public V get(K key) {
63+
public Bitmap get(String key) {
6264
return cache.get(key);
6365
}
6466

6567
@Override
66-
public void remove(K key) {
68+
public void remove(String key) {
6769
cache.remove(key);
6870
}
6971

@@ -73,7 +75,7 @@ public void clear() {
7375
}
7476

7577
@Override
76-
public Collection<K> keys() {
78+
public Collection<String> keys() {
7779
return cache.keys();
7880
}
7981
}

library/src/com/nostra13/universalimageloader/cache/memory/impl/LRULimitedMemoryCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
3737
* @since 1.3.0
3838
*/
39-
public class LRULimitedMemoryCache extends LimitedMemoryCache<String, Bitmap> {
39+
public class LRULimitedMemoryCache extends LimitedMemoryCache {
4040

4141
private static final int INITIAL_CAPACITY = 10;
4242
private static final float LOAD_FACTOR = 1.1f;

library/src/com/nostra13/universalimageloader/cache/memory/impl/LargestLimitedMemoryCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
3838
* @since 1.0.0
3939
*/
40-
public class LargestLimitedMemoryCache extends LimitedMemoryCache<String, Bitmap> {
40+
public class LargestLimitedMemoryCache extends LimitedMemoryCache {
4141
/**
4242
* Contains strong references to stored objects (keys) and sizes of the objects. If hard cache
4343
* size will exceed limit then object with the largest size is deleted (but it continue exist at

0 commit comments

Comments
 (0)