]> WPIA git - gigi.git/blob - src/org/cacert/gigi/dbObjects/ObjectCache.java
Move the "dbObject"s to their own package.
[gigi.git] / src / org / cacert / gigi / dbObjects / ObjectCache.java
1 package org.cacert.gigi.dbObjects;
2
3 import java.lang.ref.WeakReference;
4 import java.util.HashMap;
5
6 public class ObjectCache<T extends IdCachable> {
7
8     HashMap<Integer, WeakReference<T>> hashmap = new HashMap<>();
9
10     public void put(T c) {
11         hashmap.put(c.getId(), new WeakReference<T>(c));
12     }
13
14     public T get(int id) {
15         WeakReference<T> res = hashmap.get(id);
16         if (res != null) {
17             return res.get();
18         }
19         return null;
20     }
21 }