public class ConcurrentLRUTemplateCache extends Object implements TemplateCache
TemplateCache
implementation to cache TemplateContentData
using LRU replacement policy based on access order.
If no capacity specified, use default value of 5 MB.
If no time to live threshold specified, use default value of 1 day.Modifier and Type | Class and Description |
---|---|
static class |
ConcurrentLRUTemplateCache.Builder
Concurrent LRU Template Cache Builder.
|
Modifier and Type | Field and Description |
---|---|
protected long |
capacity
Custom capacity.
|
protected Map<String,AccessOrderedTemplateContentData> |
templateDataMap
Template data map.
|
protected Queue<AccessOrderedTemplateContentData> |
templateOrderQueue
Template order queue.
|
protected long |
timeToLiveThreshold
Custom TTL.
|
Modifier | Constructor and Description |
---|---|
protected |
ConcurrentLRUTemplateCache(long capacity,
long timeToLiveThreshold)
Constructor for ConcurrentLRUTemplateCache.
|
Modifier and Type | Method and Description |
---|---|
static ConcurrentLRUTemplateCache.Builder |
builder()
Static method which builds an instance of Builder.
|
TemplateContentData |
get(String identifier)
Retrieve
TemplateContentData from cache. |
int |
getCurrentCapacity()
Get cache current capacity.
|
boolean |
isEmpty()
Check whether cache is empty.
|
void |
put(String identifier,
TemplateContentData templateContentData)
Insert
TemplateContentData into cache, assign identifier to entry. |
int |
size()
Get cache size.
|
protected final long capacity
protected final long timeToLiveThreshold
protected final Map<String,AccessOrderedTemplateContentData> templateDataMap
protected final Queue<AccessOrderedTemplateContentData> templateOrderQueue
protected ConcurrentLRUTemplateCache(long capacity, long timeToLiveThreshold)
capacity
- custom capacity.timeToLiveThreshold
- custom TTL.public static ConcurrentLRUTemplateCache.Builder builder()
ConcurrentLRUTemplateCache.Builder
.public int size()
public boolean isEmpty()
public int getCurrentCapacity()
public void put(String identifier, TemplateContentData templateContentData)
TemplateContentData
into cache, assign identifier to entry.
If template size is larger than total cache capacity, no caching.
If there's not enough capacity for new entry, remove eldest ones until have capacity to insert.put
in interface TemplateCache
identifier
- template identifiertemplateContentData
- TemplateContentData
public TemplateContentData get(String identifier)
TemplateContentData
from cache.get
in interface TemplateCache
identifier
- template identifierTemplateContentData
if exists and it is fresh, otherwise return nullCopyright © 2023. All rights reserved.