Rice Pastry API

rice.persistence
Class LRUCache

java.lang.Object
  |
  +--rice.persistence.LRUCache
All Implemented Interfaces:
Cache, Catalog

public class LRUCache
extends java.lang.Object
implements Cache

This class is an encapsulation of a least-recently-used (LRU) cache. It uses the provided storage service in order to store the cached data. If the Storage provides non-corruption services, these services will also be provided by this cache.


Constructor Summary
LRUCache(rice.persistence.Storage storage, int maximumSize)
          Builds a LRU cache given a storage object to store the cached data in and a maximum cache size.
 
Method Summary
 void cache(rice.p2p.commonapi.Id id, java.io.Serializable obj, rice.Continuation c)
          Caches an object in this storage.
 boolean exists(rice.p2p.commonapi.Id id)
          Returns whether or not an object is cached in the location id.
 void exists(rice.p2p.commonapi.Id id, rice.Continuation c)
          Returns whether or not an object is cached in the location id.
 void getMaximumSize(rice.Continuation c)
          Returns the maximum size of the cache, in bytes.
 void getObject(rice.p2p.commonapi.Id id, rice.Continuation c)
          Returns the object identified by the given id.
 void getTotalSize(rice.Continuation c)
          Returns the total size of the stored data in bytes.
 rice.p2p.commonapi.IdSet scan(rice.p2p.commonapi.IdRange range)
          Return the objects identified by the given range of ids.
 void scan(rice.p2p.commonapi.IdRange range, rice.Continuation c)
          Return the objects identified by the given range of ids.
 void setMaximumSize(int size, rice.Continuation c)
          Sets the maximum size of the cache, in bytes.
 void uncache(rice.p2p.commonapi.Id id, rice.Continuation c)
          Removes the object from the list of cached objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LRUCache

public LRUCache(rice.persistence.Storage storage,
                int maximumSize)
Builds a LRU cache given a storage object to store the cached data in and a maximum cache size.

Parameters:
storage - The storage service to use as a back-end storage
maximumSize - The maximum size, in bytes, of storage to use
Method Detail

cache

public void cache(rice.p2p.commonapi.Id id,
                  java.io.Serializable obj,
                  rice.Continuation c)
Caches an object in this storage. This method is non-blocking. If the object has already been stored at the location id, this method has the effect of calling uncachr(id) followed by cache(id, obj). This method finishes by calling receiveResult() on the provided continuation with whether or not the object was cached. Note that the object may not actually be cached due to the cache replacement policy. Returns True if the cache actaully stores the object, else False (through receiveResult on c).

Specified by:
cache in interface Cache
Parameters:
id - The object's id.
obj - The object to cache.
c - The command to run once the operation is complete

uncache

public void uncache(rice.p2p.commonapi.Id id,
                    rice.Continuation c)
Removes the object from the list of cached objects. This method is non-blocking. If the object was not in the cached list in the first place, nothing happens and False is returned. Returns True if the action succeeds, else False (through receiveResult on c).

Specified by:
uncache in interface Cache
Parameters:
c - The command to run once the operation is complete

exists

public boolean exists(rice.p2p.commonapi.Id id)
Returns whether or not an object is cached in the location id.

Specified by:
exists in interface Catalog
Parameters:
id - The id of the object in question.
Returns:
Whether or not an object is present at id.

exists

public void exists(rice.p2p.commonapi.Id id,
                   rice.Continuation c)
Returns whether or not an object is cached in the location id. The result is returned via the receiveResult method on the provided Continuation with an Boolean represnting the result.

Specified by:
exists in interface Catalog
Parameters:
c - The command to run once the operation is complete
id - The id of the object in question.
Returns:
Whether or not an object is present at id.

getObject

public void getObject(rice.p2p.commonapi.Id id,
                      rice.Continuation c)
Returns the object identified by the given id.

Specified by:
getObject in interface Catalog
Parameters:
id - The id of the object in question.
c - The command to run once the operation is complete
Returns:
The object, or null if there is no cooresponding object (through receiveResult on c).

scan

public void scan(rice.p2p.commonapi.IdRange range,
                 rice.Continuation c)
Return the objects identified by the given range of ids. The IdSet returned contains the Ids of the stored objects. The range is partially inclusive, the lower range is inclusive, and the upper exclusive. When the operation is complete, the receiveResult() method is called on the provided continuation with a IdSet result containing the resulting IDs.

Specified by:
scan in interface Catalog
Parameters:
c - The command to run once the operation is complete
Returns:
The idset containg the keys

scan

public rice.p2p.commonapi.IdSet scan(rice.p2p.commonapi.IdRange range)
Return the objects identified by the given range of ids. The IdSet returned contains the Ids of the stored objects. The range is partially inclusive, the lower range is inclusive, and the upper exclusive. NOTE: This method blocks so if the behavior of this method changes and uses the disk, this method may be deprecated.

Specified by:
scan in interface Catalog
Parameters:
range - The range to query
Returns:
The idset containg the keys

getMaximumSize

public void getMaximumSize(rice.Continuation c)
Returns the maximum size of the cache, in bytes. The result is returned via the receiveResult method on the provided Continuation with an Integer representing the size.

Specified by:
getMaximumSize in interface Cache
Parameters:
c - The command to run once the operation is complete

getTotalSize

public void getTotalSize(rice.Continuation c)
Returns the total size of the stored data in bytes. The result is returned via the receiveResult method on the provided Continuation with an Integer representing the size.

Specified by:
getTotalSize in interface Catalog
Parameters:
c - The command to run once the operation is complete
Returns:
The total size, in bytes, of data stored.

setMaximumSize

public void setMaximumSize(int size,
                           rice.Continuation c)
Sets the maximum size of the cache, in bytes. Setting this value to a smaller value than the current value may result in object being evicted from the cache.

Specified by:
setMaximumSize in interface Cache
Parameters:
size - The new maximum size, in bytes, of the cache.
c - The command to run once the operation is complete
Returns:
The success or failure of the setSize operation (through receiveResult on c).

Rice Pastry API

Copyright © 2001 - Rice Pastry.


Imprint-Dataprotection