| 1 | |
package org.webslinger.lang; |
| 2 | |
|
| 3 | |
public abstract class ConcurrentFreezingCache<I, K, V> extends AbstractConcurrentCache<K, V>{ |
| 4 | 1 | public static final ValueType HARD = ValueType.HARD; |
| 5 | 1 | public static final ValueType SOFT = ValueType.SOFT; |
| 6 | 1 | public static final ValueType WEAK = ValueType.WEAK; |
| 7 | |
|
| 8 | |
protected final Freezer<I, K> freezer; |
| 9 | |
|
| 10 | |
public ConcurrentFreezingCache(Class<?> owner, String field, String label, Freezer<I, K> freezer) { |
| 11 | 0 | this(owner, field, label, null, false, freezer); |
| 12 | 0 | } |
| 13 | |
|
| 14 | |
public ConcurrentFreezingCache(Class<?> owner, String field, String label, boolean sorted, Freezer<I, K> freezer) { |
| 15 | 0 | this(owner, field, label, null, sorted, freezer); |
| 16 | 0 | } |
| 17 | |
|
| 18 | |
public ConcurrentFreezingCache(Class<?> owner, String field, String label, AbstractConcurrentCache.ValueType valueType, Freezer<I, K> freezer) { |
| 19 | 32 | this(owner, field, label, valueType, false, freezer); |
| 20 | 32 | } |
| 21 | |
|
| 22 | |
public ConcurrentFreezingCache(Class<?> owner, String field, String label, AbstractConcurrentCache.ValueType valueType, boolean sorted, Freezer<I, K> freezer) { |
| 23 | 32 | super(owner, field, label, valueType, sorted); |
| 24 | 32 | this.freezer = freezer; |
| 25 | 32 | } |
| 26 | |
|
| 27 | |
public V get(I id) throws Exception { |
| 28 | 2829 | return get(id, freezer.freeze(id)); |
| 29 | |
} |
| 30 | |
|
| 31 | |
public V get(I id, boolean create) throws Exception { |
| 32 | 0 | return get(id, freezer.freeze(id), create); |
| 33 | |
} |
| 34 | |
|
| 35 | |
protected abstract V createValue(Object id, K key) throws Exception; |
| 36 | |
} |