-
-
Save maniksurtani/97c62352347e61d60768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A task that is invoked by multiple threads, once for each entry | |
// Implementations MUST be threadsafe, as processEntry will be invoked concurrently. | |
// Ideally, don't maintain state in your implementation! | |
public interface CacheLoaderTask { | |
void processEntry(LazyInternalCacheEntry entry, TaskContext context); | |
} | |
// Very similar to an InternalCacheEntry, except deserialisation of contents happens lazily, as and when requested. | |
// Also, direct access to the underlying byte buffers that back this entry are exposed. | |
public interface LazyInternalCacheEntry { | |
Object getKey(); | |
InternalCacheValue getInternalCacheValue(); | |
/** | |
* Same as getInternalCacheValue() but doesn't de-serialize the value. Only the metadata and timestamps. | |
*/ | |
InternalCacheValue getSparseInternalCacheValue(); | |
ByteBuffer getKeyBuffer(); | |
ByteBuffer getInternalCacheValueBuffer(); | |
} | |
public interface TaskContext { | |
/** | |
* If invoked, will *attempt* a best effort to stop processing further tasks. Tasks already started will not be stopped. | |
*/ | |
void stopProcessingEntries(); | |
/** | |
* A best effort calculation on the number of entries processed, including the current entry. Susceptible to race conditions and may not be absolutely accurate. | |
*/ | |
int getNumberOfEntriesProcessed(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's my API suggestion: https://gist.github.com/mmarkus/6195428