|
2 | 2 |
|
3 | 3 | import java.nio.file.Path; |
4 | 4 |
|
| 5 | +import com.g2forge.alexandria.java.adt.name.INamed; |
5 | 6 | import com.g2forge.alexandria.java.function.IFunction1; |
6 | 7 | import com.g2forge.alexandria.java.function.IFunction2; |
7 | 8 | import com.g2forge.reassert.cache.store.ICacheStore; |
8 | 9 |
|
9 | | -public interface ICacheAreaDescriptor<K, V> { |
| 10 | +/** |
| 11 | + * A descriptor for a cache area. The methods on this interface allow the cache to learn how to compute values, load & store keys, exceptions, and values, |
| 12 | + * and where to create cache entries within this area. Caches should cache exceptions when possible, and should verify that the key for any cache entry matches |
| 13 | + * to expected key in case of collisions in {@link #getHashFunction()}. |
| 14 | + * |
| 15 | + * @param <K> |
| 16 | + * The type of keys for this cache area. |
| 17 | + * @param <V> |
| 18 | + * The type of values for this cache area. |
| 19 | + */ |
| 20 | +public interface ICacheAreaDescriptor<K, V> extends INamed<Path> { |
| 21 | + /** |
| 22 | + * Storage abstraction for exceptions from {@link #getFunction()}. Exceptions are cached in order to improve performance. See |
| 23 | + * {@link com.g2forge.reassert.cache.store.ObjectSerializationCacheStore} which is strongly recommended as being one of the few ways to serialize and |
| 24 | + * deserialize exceptions in Java. |
| 25 | + * |
| 26 | + * @return Storage abstraction for the cache function exceptions. |
| 27 | + */ |
| 28 | + public ICacheStore<Exception> getExceptionConverter(); |
| 29 | + |
| 30 | + /** |
| 31 | + * Get the name of the on-disk exception within the cache entry. |
| 32 | + * |
| 33 | + * @return The name of the on-disk exception within the cache entry. |
| 34 | + */ |
| 35 | + public String getExceptionName(); |
| 36 | + |
| 37 | + /** |
| 38 | + * The function to cache. Accepts the key, and the on-disk path where the value should be cached. The path should only be used if this function is |
| 39 | + * downloading something, or otherwise making a copy of a large file structure. The path will not exist when this function is called, but it can be created |
| 40 | + * by this function. If <code>path</code> is <code>null</code> then the function should download any files to a temp directory instead. Returns the actual |
| 41 | + * value. |
| 42 | + * |
| 43 | + * @return The function whose results we are caching. A function from key and local path to actual value. |
| 44 | + */ |
10 | 45 | public IFunction2<? super K, ? super Path, ? extends V> getFunction(); |
11 | 46 |
|
| 47 | + /** |
| 48 | + * Key hash function used to determine the on-disk location of the cache entry within the cache area. This function should return a (hopefully, but not |
| 49 | + * necessarily always) unique path for each key, which is valid on this operating system. <code>key -> Paths.get(key.toString())</code>, or something |
| 50 | + * equally simple, is acceptable if there are never OS-disallowed characters in that string. |
| 51 | + * |
| 52 | + * @return The key hash function. |
| 53 | + */ |
12 | 54 | public IFunction1<? super K, ? extends Path> getHashFunction(); |
13 | 55 |
|
| 56 | + /** |
| 57 | + * Storage abstraction for the cache keys. See implementations of {@link ICacheStore}. |
| 58 | + * |
| 59 | + * @return Storage abstraction for the cache keys |
| 60 | + */ |
14 | 61 | public ICacheStore<K> getKeyConverter(); |
15 | 62 |
|
| 63 | + /** |
| 64 | + * Get the name of the on-disk key within the cache entry. |
| 65 | + * |
| 66 | + * @return The name of the on-disk key within the cache entry. |
| 67 | + */ |
16 | 68 | public String getKeyName(); |
17 | 69 |
|
| 70 | + /** |
| 71 | + * A name for this cache area. Should be unique to whatever is being cached and stable over time. <code>Paths.get(getClass().getSimpleName())</code> is |
| 72 | + * often a reasonable value. |
| 73 | + */ |
18 | 74 | public Path getName(); |
19 | 75 |
|
| 76 | + /** |
| 77 | + * Storage abstraction for the cache values. See implementations of {@link ICacheStore}. |
| 78 | + * |
| 79 | + * @return Storage abstraction for the cache values. |
| 80 | + */ |
20 | 81 | public ICacheStore<V> getValueConverter(); |
21 | | - |
22 | | - public ICacheStore<Exception> getExceptionConverter(); |
23 | 82 |
|
| 83 | + /** |
| 84 | + * Get the name of the on-disk value within the cache entry. |
| 85 | + * |
| 86 | + * @return The name of the on-disk value within the cache entry. |
| 87 | + */ |
24 | 88 | public String getValueName(); |
25 | | - |
26 | | - public String getExceptionName(); |
27 | 89 | } |
0 commit comments