tango.net.cluster.QueuedCache

License:

BSD style: see license.txt

Version:

April 2004: Initial release

Author:

Kris
class QueuedCache(K, V) : ICache!(K, V) #
QueuedCache extends the basic cache type by adding a limit to the number of items contained at any given time. In addition, QueuedCache sorts the cache entries such that those entries frequently accessed are at the head of the queue, and those least frequently accessed are at the tail. When the queue becomes full, old entries are dropped from the tail and are reused to house new cache entries.
This is great for keeping commonly accessed items around, while limiting the amount of memory used. Typically, the queue size would be set in the hundreds (perhaps thousands).

Note that key.init cannot be used as a valid key

this(uint capacity) #
Construct a cache with the specified maximum number of entries. Additions to the cache beyond this number will reuse the slot of the least-recently-referenced cache entry. The concurrency level indicates approximately how many threads will content for write access at one time.
bool get(K key, inout V value) [synchronized] #
Get the cache entry identified by the given key
V get(K key) [synchronized] #
Get the cache entry identified by the given key
bool put(K key, V value, Time time = Time.init) [synchronized] #
Place an entry into the cache and associate it with the provided key. Note that there can be only one entry for any particular key. If two entries are added with the same key, the second effectively overwrites the first.
An optional time value allows for testing whether an existing entry is newer than our provided one. Where the provided time value is lesser, the put() operation will be abandoned and false is returned.

Returns true if the cache was updated.

bool put(K peek, K delegate() key, V delegate() value, Time time = Time.init) [synchronized] #
Same as above, but being careful to avoid heap activity where the provided key and value are potentially aliased
V remove(K key, Time time = Time.max) [synchronized] #
Remove (and return) the cache entry associated with the provided key. Returns null if there is no such entry.
int opApply(int delegate(inout K key, inout V value) dg) [synchronized] #
Iterate over elements
Note that this needs to be synchronized, and can therefore be very costly in terms of blocking other threads. Use with caution
QueuedEntry* lookup(K key) [private, final] #
QueuedEntry* deReference(QueuedEntry* entry) [private, final] #
Place a cache entry at the tail of the queue. This makes it the least-recently referenced.
QueuedEntry* reReference(QueuedEntry* entry) [private, final] #
Move a cache entry to the head of the queue. This makes it the most-recently referenced.
QueuedEntry* addEntry() [private, final] #
Add an entry into the queue. If the queue is full, the least-recently-referenced entry is reused for the new addition.
struct QueuedEntry [private, static] #
A doubly-linked list entry, used as a wrapper for queued cache entries.
QueuedEntry* set(K key, V value, Time time) #
Set this entry with the given arguments.
QueuedEntry* prepend(QueuedEntry* before) #
Insert this entry into the linked-list just in front of the given entry.
QueuedEntry* append(QueuedEntry* after) #
Add this entry into the linked-list just after the given entry.
QueuedEntry* extract() #
Remove this entry from the linked-list. The previous and next entries are patched together appropriately.