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

ICache.d

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003         @file ICache.d
00004         
00005         Copyright (c) 2004 Kris Bell
00006         
00007         This software is provided 'as-is', without any express or implied
00008         warranty. In no event will the authors be held liable for damages
00009         of any kind arising from the use of this software.
00010         
00011         Permission is hereby granted to anyone to use this software for any 
00012         purpose, including commercial applications, and to alter it and/or 
00013         redistribute it freely, subject to the following restrictions:
00014         
00015         1. The origin of this software must not be misrepresented; you must 
00016            not claim that you wrote the original software. If you use this 
00017            software in a product, an acknowledgment within documentation of 
00018            said product would be appreciated but is not required.
00019 
00020         2. Altered source versions must be plainly marked as such, and must 
00021            not be misrepresented as being the original software.
00022 
00023         3. This notice may not be removed or altered from any distribution
00024            of the source.
00025 
00026         4. Derivative works are permitted, but they must carry this notice
00027            in full and credit the original source.
00028 
00029 
00030                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00031 
00032         
00033         @version        Initial version, April 2004      
00034         @author         Kris
00035 
00036 
00037 *******************************************************************************/
00038 
00039 module mango.cache.model.ICache;
00040 
00041 private import mango.cache.model.IPayload;
00042 
00043 /******************************************************************************
00044 
00045         Defines what a cache instance exposes. We try to keep the basic
00046         operations to a reasonable minimum.
00047 
00048 ******************************************************************************/
00049 
00050 interface ICache
00051 {
00052         /**********************************************************************
00053 
00054                 Get the cache entry identified by the given key
00055 
00056         **********************************************************************/
00057 
00058         IPayload get (char[] key);
00059 }
00060 
00061 
00062 /******************************************************************************
00063 
00064         Defines what a modifiable cache instance exposes
00065 
00066 ******************************************************************************/
00067 
00068 interface IMutableCache : ICache
00069 {
00070         /**********************************************************************
00071 
00072                 Place an entry into the cache and associate it with the
00073                 provided key. Note that there can be only one entry for
00074                 any particular key. If two keys entries are added with
00075                 the same key, the second effectively overwrites the first.
00076 
00077                 Returns what it was given
00078 
00079         **********************************************************************/
00080 
00081         IPayload put (char[] key, IPayload entry);
00082 
00083         /**********************************************************************
00084 
00085                 Remove (and return) the cache entry associated with the 
00086                 provided key. The entry will not be removed if it's time
00087                 attribute is newer than the (optional) specified 'timelimit'. 
00088 
00089                 Returns null if there is no such entry. 
00090 
00091         **********************************************************************/
00092 
00093         IPayload extract (char[] key, ulong timeLimit = ulong.max);
00094 
00095         /**********************************************************************
00096 
00097                 This is a factory for producing an ICache instance upon
00098                 the cache content. The provided loader will populate the
00099                 cache whenever a stale or missing entry is seen
00100 
00101         **********************************************************************/
00102 
00103         ICache bind (ICacheLoader loader);
00104 }
00105 
00106 
00107 /******************************************************************************
00108 
00109         Manages the lifespan of an ICache entry. These loaders effectively
00110         isolate the cache from whence the content is derived. It's a good
00111         idea to employ this abstraction where appropriate, since it allows
00112         the cache source to change with minimal (if any) impact on client
00113         code.
00114 
00115 ******************************************************************************/
00116 
00117 interface ICacheLoader
00118 {
00119         /**********************************************************************
00120 
00121                 Test the cache entry to see if it is still valid. A true
00122                 return value indicates the entry is valid, whereas false
00123                 flags the entry as stale. The latter case will cause the
00124                 load() method to be invoked.
00125 
00126         **********************************************************************/
00127 
00128         bool test (IPayload p);
00129 
00130         /**********************************************************************
00131 
00132                 Load a cache entry from wherever the content is persisted.
00133                 The 'time' argument represents that belonging to a stale
00134                 entry, which can be used to optimize the loader operation
00135                 (no need to perform a full load where there's already a 
00136                 newer version in an L2 cache). This 'time' value will be
00137                 long.min where was no such stale entry.
00138 
00139         **********************************************************************/
00140 
00141         IPayload load (char[] key, ulong time);
00142 }
00143 
00144 
00145 /******************************************************************************
00146 
00147         Manages the loading of ICache entries remotely, on the device
00148         that actually contains the remote cache entry. The benefit of
00149         this approach lies in the ability to 'gate' access to specific
00150         resources across the entire network. That is; where particular
00151         entries are prohibitively costly to construct, it's worthwhile
00152         ensuring that cost is reduced to a bare minimum. These remote
00153         loaders allow the cache host to block multiple network clients
00154         until there's a new entry available. Without this mechanism, 
00155         it's possible for multiple network clients to request the same
00156         entry simultaneously; therefore increasing the overall cost. 
00157         The end result is similar to that of a distributed-transaction.
00158          
00159 ******************************************************************************/
00160 
00161 interface IRemoteCacheLoader : IPayload, ICacheLoader
00162 {
00163         /**********************************************************************
00164         
00165                 Return the sleep duration between attempts to retrieve 
00166                 a locked cache entry. Consider setting this duration to
00167                 be approximately half the time you'd expect each remote 
00168                 cache-load to typically consume. The 'wait' argument is
00169                 a representation of how many microseconds have added up
00170                 while waiting. When this value exceeds some limit, you
00171                 should return zero to indicate a timeout condition.
00172 
00173                 Note that the return value should be in microseconds ~  
00174                 one tenth of a second equals 100_000 microseconds. Note
00175                 also that you might consider returning a sliding value,
00176                 where the pause starts off small, and increases as time
00177                 passes. A simple implementation might look like this:
00178 
00179                 @code
00180                 return (wait > 2_000_000) ? 0 : 10_000 + wait / 2;
00181                 @endcode
00182 
00183         **********************************************************************/
00184 
00185         uint pause (uint wait);
00186 }
00187 

Generated on Sat Dec 24 17:28:33 2005 for Mango by  doxygen 1.4.0