Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

VirtualCache Class Reference

Inheritance diagram for VirtualCache:

QueuedCache List of all members.

Public Member Functions

 this (IBitBucket bucket, uint capacity, uint concurrency=16)
IBitBucket getBucket ()
IPayload get (char[] key)
IPayload extract (char[] key, ulong timeLimit=ulong.max)
IPayload put (char[] key, IPayload entry)

Private Member Functions

 this (uint capacity, uint concurrency=16)
IPayload extract (char[] key)
QueuedEntry createQueuedEntry (char[] key, IPayload entry)

Private Attributes

Buffer buffer
IBitBucket bucket
PickleReader reader
PickleWriter writer

Detailed Description

Uses a combination of QueuedCache and IBitBucket to spill LRU cache entries from cache memory, and then recover them intact. Each cache entry placed into a VirtualCache should have support for the IPicked interface, such that its content will be written externally, and restored correctly. In practical terms, this means the IPayload's placed here should override the read(), write(), create() and getGuid() default implementations.

Here's a contrived example:

// create a FileBucket as a place to spill cache entries auto FileBucket bucket = new FileBucket (new FilePath("bucket.bin"), FileBucket.HalfK); // note that we specify only two entries, to ensure we'll spill // entries to the FileBucket VirtualCache cache = new VirtualCache (bucket, 2); // need to tell registry how to resurrect our spilled entries PickleRegistry.enroll (new Payload); // stuff a few entries into the cache. Adding the third entry // will cause a spillover to the FileBucket cache.put ("a", new Payload); cache.put ("b", new Payload); cache.put ("c", new Payload); // retrieve entries such that we cause one more spillage and // two resurrections assert (cache.get("a")); assert (cache.get("c")); assert (cache.get("b"));

Definition at line 89 of file VirtualCache.d.


Member Function Documentation

this IBitBucket  bucket,
uint  capacity,
uint  concurrency = 16
[inline]
 

Create a VirtualCache with the provided IBitBucket and maximum capacity. Said capacity sets the waterline mark whereby further additions to the cache will cause least recently used entries to be spilled to the IBitBucket. The concurrency level indicates approximately how many threads will content for write access at one time.

Definition at line 107 of file VirtualCache.d.

References bucket, buffer, IBitBucket::getBufferSize(), PickleReader, PickleWriter, reader, and writer.

IBitBucket getBucket  )  [inline]
 

Return the IBitBucket used by this VirtualCache

Definition at line 132 of file VirtualCache.d.

References bucket.

IPayload get char[]  key  )  [inline]
 

Return an entry from this cache. If the given key is not found, we attempt to resurrect the entry via data from our IBitBucket.

Returns the IPayload upon success, null if the given key was never placed into the cache.

Reimplemented from QueuedCache.

Definition at line 148 of file VirtualCache.d.

References bucket, IBitBucket::get(), reader, and PickleReader::thaw().

Referenced by testVirtualCache().

IPayload extract char[]  key,
ulong  timeLimit = ulong.max
[inline]
 

Remove an entry from this cache, and from the associated IBitBucket too.

Reimplemented from QueuedCache.

Definition at line 177 of file VirtualCache.d.

References bucket, and IBitBucket::remove().

IPayload put char[]  key,
IPayload  entry
[inline]
 

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 keys entries are added with the same key, the second one overwrites the first.

Copy entry to Bucket immediately, so we avoid writing it each time it gets bumped from the cache.

Reimplemented from QueuedCache.

Definition at line 200 of file VirtualCache.d.

References bucket, buffer, Buffer::clear(), PickleWriter::freeze(), IBitBucket::put(), Buffer::toString(), and writer.

Referenced by testVirtualCache().

this uint  capacity,
uint  concurrency = 16
[inline, inherited]
 

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.

Reimplemented from PlainCache.

Definition at line 79 of file QueuedCache.d.

References QueuedCache::capacity.

IPayload extract char[]  key  )  [inline, inherited]
 

Remove (and return) the cache entry associated with the provided key. Returns null if there is no such entry.

Definition at line 105 of file PlainCache.d.

References HashMap::remove().

Referenced by testPlainCache().

QueuedEntry createQueuedEntry char[]  key,
IPayload  entry
[inline, inherited]
 

Overridable factory for creating list entries.

Definition at line 167 of file QueuedCache.d.


Member Data Documentation

Buffer buffer [private]
 

Definition at line 91 of file VirtualCache.d.

Referenced by put(), and this().

IBitBucket bucket [private]
 

Definition at line 92 of file VirtualCache.d.

Referenced by extract(), get(), getBucket(), put(), and this().

PickleReader reader [private]
 

Definition at line 93 of file VirtualCache.d.

Referenced by get(), and this().

PickleWriter writer [private]
 

Definition at line 94 of file VirtualCache.d.

Referenced by put(), and this().


The documentation for this class was generated from the following file:
Generated on Sun Nov 7 19:07:16 2004 for Mango by doxygen 1.3.6