tango.net.cluster.NetworkCache

License:

BSD style: see license.txt

Version:

July 2004: Initial release

Author:

Kris
class NetworkCache : CacheInvalidator #
A gateway to the network cache. From here you can easily place IMessage objects into the network cluster, copy them and remove them. A cluster cache is spread out across many servers within the network. Each cache entry is associated with a 'channel', which is effectively the name of a cache instance within the cluster. See ComboCache also. The basic procedure is so:
1
2
3
4
5
6
7
8
9
import tango.net.cluster.NetworkCache;
import tango.net.cluster.tina.Cluster;

auto cluster = new Cluster (...);
auto cache = new NetworkCache (cluster, ...);

cache.put (...);
cache.get ();
cache.invalidate (...);
Note that any content placed into the cache must implement the IMessage interface, and must be enrolled with the Registry, as it may be frozen and thawed as it travels around the network.
this(ICluster cluster, char[] channel) #
Construct a NetworkCache using the QOS (cluster) provided, and hook it onto the specified channel. Each subsequent operation is tied to this channel.
IMessage get(char[] key) #
Returns a copy of the cluster cache entry corresponding to the provided key. Returns null if there is no such entry.
IMessage extract(char[] key) #
Remove and return the cache entry corresponding to the provided key.
bool put(char[] key, IMessage message) #
Set a cluster cache entry.
Place an entry into the network cache, replacing the entry with the identical key. Where message.time is set, it will be used to test for newer cache entries than the one being sent i.e. if someone else placed a newer entry into the cache, that one will remain.

The msg will be placed into one or more cluster hosts (depending upon QOS)

Returns true if the cache entry was inserted, false if the cache server already has an exiting key with a more recent timestamp (where message.time is set).

class NetworkCombo : NetworkCache #
A combination of a local cache, cluster cache, and CacheInvalidatee. The two cache instances are combined such that they represent a classic level1/level2 cache. The CacheInvalidatee ensures that the level1 cache maintains coherency with the cluster.
this(ICluster cluster, char[] channel, uint capacity) #
Construct a ComboCache for the specified local cache, and on the given cluster channel.
IMessage get(char[] key, IMessage delegate(IMessage) dg) #
Get an IMessage from the local cache, and revert to the cluster cache if it's not found. Cluster lookups will *not* place new content into the local cache without confirmation: the supplied delegate must perform the appropriate cloning of cluster entries before they will be placed into the local cache. This delegate would typically invoke the clone() method on the provided network message; behaviour is undefined where a delegate simply returns a message without the appropriate cloning steps.
Returns null if the entry does not exist in either the local or remote cache, or if the delegate returned null. Returns the cache entry otherwise.
bool put(char[] key, IMessage message, bool coherent = false) #
Place a new entry into the cache. This will also place the entry into the cluster, and optionally invalidate all other local cache instances across the network. If a cache entry exists with the same key, it is replaced.
Where message.time is set, it will be used to test for newer cache entries than the one being sent i.e. if a newer entry exists in the cache, that one will remain. Note that when using the coherency option you should ensure your IMessage has a valid time stamp, since that is used to invalidate appropriate cache listeners in the cluster. You can use the getTime() method to retrieve a current millisecond count.

Returns true if the cache entry was inserted, false if the cache server already has an exiting key with a more recent timestamp (where message.time is set).

IMessage extract(char[] key) #
Remove and return the cache entry corresponding to the provided key. Synchronously extracts the entry from the cluster, and returns the entry from the local cache if there is one there; null otherwise