lbg.protocol.data
Class ByteBoundedSlottedLRUCache<K extends java.lang.Comparable<? extends K>>
java.lang.Object
lbg.protocol.data.Cache<K>
lbg.protocol.data.SlottedLRUCache<K>
lbg.protocol.data.ByteBoundedSlottedLRUCache<K>
- Type Parameters:
K
- The type of the entries
public class ByteBoundedSlottedLRUCache<K extends java.lang.Comparable<? extends K>>
- extends SlottedLRUCache<K>
This class implements a cache of a size bounded in number of entries.
- Author:
- Xavier Dalem
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
ByteBoundedSlottedLRUCache
public ByteBoundedSlottedLRUCache(int capacity,
long byte_limit)
add
public Metadata<K> add(K entry,
Metadata<K> meta)
throws VetoException,
java.lang.IllegalStateException
- Description copied from class:
SlottedLRUCache
- Adds an entry to the cache.
If the cache is full, an entry will be evicted if possible.
If the entry was already present, it is updated as having been used
recently (i.e. put on top of the LRU queue).
Setting meta data for an existing entry doesn't replace the existing
metadata. Either Cache.getMetadata(Comparable)
and modify it or
SlottedLRUCache.remove(Comparable)
then add it back.
- Overrides:
add
in class SlottedLRUCache<K extends java.lang.Comparable<? extends K>>
- Parameters:
entry
- The entry to addmeta
- Metadata concerning this entry
- Returns:
- The entry that was popped, if any
- Throws:
VetoException
- if one entry should be popped but all are veto'ed
java.lang.IllegalStateException
canAdd
public boolean canAdd(Metadata<K>[] entries,
boolean mindVeto)
- Description copied from class:
Cache
- Checks if the cache can hold all entries.
The check is based on the current veto, as this method returns true if
all entries not in the veto can be stored in the remaining space.
- Overrides:
canAdd
in class SlottedLRUCache<K extends java.lang.Comparable<? extends K>>
- Parameters:
entries
- The entries that would be addedmindVeto
- true if the current veto should be taken into
account. If false, it will be considered that the veto could
be removed before actually inserting the data. In the latter case,
adding without clearing the veto could fail even if the method returns
true
- Returns:
- true if all entries can potentially be added.
isFull
public boolean isFull()
- Overrides:
isFull
in class SlottedLRUCache<K extends java.lang.Comparable<? extends K>>
remove
public Metadata<K> remove(K entry)
throws VetoException
- Description copied from class:
Cache
- Removes an entry from the cache.
- Overrides:
remove
in class SlottedLRUCache<K extends java.lang.Comparable<? extends K>>
- Parameters:
entry
- The entry to remove
- Returns:
- true if the entry was in the cache
- Throws:
VetoException
- if the entry is veto'ed
Copyright (c) 2005-2008, Cyril Briquet, parts Xavier Dalem.