-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathBlobKeyCache.java
More file actions
58 lines (49 loc) · 1.62 KB
/
Copy pathBlobKeyCache.java
File metadata and controls
58 lines (49 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package gaeexample.blobstore;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.sf.jsr107cache.Cache;
import net.sf.jsr107cache.CacheException;
import net.sf.jsr107cache.CacheManager;
import com.google.appengine.api.blobstore.BlobKey;
public class BlobKeyCache {
private static BlobKeyCache bc = null;
private Cache cache;
public BlobKeyCache() {
if (cache == null) {
try {
cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
} catch (CacheException e) {
e.printStackTrace();
}
}
}
public static BlobKeyCache getBlobKeyCache() {
if (bc == null) {
bc = new BlobKeyCache();
}
return bc;
}
@SuppressWarnings("unchecked")
public void add(BlobKey key) {
ArrayList<BlobKey> blobList = (ArrayList<BlobKey>) cache.get("blobs");
if (blobList == null)
blobList = new ArrayList<BlobKey>();
blobList.add(key);
blobList.remove("blobs");
cache.put("blobs", blobList);
}
@SuppressWarnings("unchecked")
public void remove(BlobKey bk) {
ArrayList<BlobKey> blobList = (ArrayList<BlobKey>) cache.get("blobs");
if (blobList != null && blobList.contains(bk))
blobList.remove(bk);
cache.put("blobs", blobList);
}
public List<BlobKey> getCache() {
ArrayList<BlobKey> blobList = (ArrayList) cache.get("blobs");
if (blobList == null)
blobList = new ArrayList<BlobKey>();
return blobList;
}
}