/** * Specify that a list of cache objects are 'dirty' and need to be saved to db * * @param types */ public void setDirty(UniqueKey<Key>... types) { synchronized (dirty) { for (UniqueKey<Key> t : types) { if (map.containsKey(t.getKey())) dirty.add(t.getKey()); } } }
public void setClean(UniqueKey<Key>... types) { synchronized (dirty) { for (UniqueKey<Key> t : types) { dirty.remove(t.getKey()); } } }
@SuppressWarnings("unchecked") /** * get a key. if varArgs is not null these values will be passed to the serializer in the case * that the cache object does not exist * * @param key cache key * @param varArgs arguments that will be passed to serializer when a key is not found * @return */ public Value get(Key key, Object... varArgs) { if (DEBUG) System.out.println(" - getting key = " + key + " contains=" + map.containsKey(key)); CacheElement o = map.get(key); // UniqueKey<Key> t = map.get(key); if (o == null) { MutableBoolean isdirty = new MutableBoolean(false); UniqueKey<Key> t = serializer.load(key, isdirty, varArgs); if (DEBUG) System.out.println(" - loaded element = " + t + " "); if (t == null) return null; o = new CacheElement(t); key = t.getKey(); synchronized (map) { map.put(key, o); } if (DEBUG) System.out.println( " - adding key = " + key + " contains=" + map.containsKey(key) + " dirty=" + dirty); if (isdirty.booleanValue()) { // / If its dirty, add to our dirty set synchronized (dirty) { dirty.add(key); } } } o.setUsed(); if (autoFlush && autoFlushTime != null) { flushOld(autoFlushTime); } return (Value) o.v; }
/** * remove a cache object using the type given * * @param type * @return */ public Value remove(UniqueKey<Key> type) { return remove(type.getKey()); }
/** * get a cache object using the key from the given param. * * @param type * @param varArgs * @return */ public Value get(UniqueKey<Key> type, Object... varArgs) { return get(type.getKey(), varArgs); }
/** * get a cache object using the key from the given param * * @param type * @return */ public Value get(UniqueKey<Key> type) { return get(type.getKey()); }