Page Speed Optimization Libraries
1.4.26.1
|
namespace SharedMemCacheData More...
#include "shared_mem_cache.h"
Classes | |
struct | Position |
Describes potential placements of a key. | |
Public Member Functions | |
SharedMemCache (AbstractSharedMem *shm_runtime, const GoogleString &filename, Timer *timer, const Hasher *hasher, int sectors, int entries_per_sector, int blocks_per_sector, MessageHandler *handler) | |
code of ExtractPosition as well. | |
bool | Initialize () |
bool | Attach () |
GoogleString | DumpStats () |
virtual void | Get (const GoogleString &key, Callback *callback) |
virtual void | Put (const GoogleString &key, SharedString *value) |
virtual void | Delete (const GoogleString &key) |
virtual const char * | Name () const |
The name of this CacheInterface -- used for logging and debugging. | |
virtual bool | IsBlocking () const |
virtual bool | IsHealthy () const |
virtual void | ShutDown () |
void | SanityCheck () |
Sanity check the cache data structures. | |
Static Public Member Functions | |
static void | GlobalCleanup (AbstractSharedMem *shm_runtime, const GoogleString &filename, MessageHandler *message_handler) |
static void | ComputeDimensions (int64 size_kb, int block_entry_ratio, int sectors, int *entries_per_sector_out, int *blocks_per_sector_out, int64 *size_cap_out) |
Static Public Attributes | |
static const int | kAssociativity = 4 |
namespace SharedMemCacheData
Abstract interface for a cache.
net_instaweb::SharedMemCache< kBlockSize >::SharedMemCache | ( | AbstractSharedMem * | shm_runtime, |
const GoogleString & | filename, | ||
Timer * | timer, | ||
const Hasher * | hasher, | ||
int | sectors, | ||
int | entries_per_sector, | ||
int | blocks_per_sector, | ||
MessageHandler * | handler | ||
) |
code of ExtractPosition as well.
Initializes the cache's settings, but does not actually touch the shared memory --- you must call Initialize or Attach (and handle them potentially returning false) to do so. The filename parameter will be used to identify the shared memory segment, so distinct caches should use distinct values.
Precondition: hasher's raw mode must produce 13 bytes or more.
bool net_instaweb::SharedMemCache< kBlockSize >::Attach | ( | ) |
Connects to already initialized state from a child process. It must be called once for every cache in every child process (that is, post-fork). Returns whether successful.
static void net_instaweb::SharedMemCache< kBlockSize >::ComputeDimensions | ( | int64 | size_kb, |
int | block_entry_ratio, | ||
int | sectors, | ||
int * | entries_per_sector_out, | ||
int * | blocks_per_sector_out, | ||
int64 * | size_cap_out | ||
) | [static] |
Computes how many entries and blocks per sector a cache with total size 'size_kb' and 'sectors' should have if there are about 'block_entry_ratio' worth of blocks of data per every entry. You probably want to underestimate this ratio somewhat, since having extra entries can reduce conflicts. Also outputs size_cap, which is the limit on object size for the resulting cache.
GoogleString net_instaweb::SharedMemCache< kBlockSize >::DumpStats | ( | ) |
Returns some statistics as plaintext.
virtual void net_instaweb::SharedMemCache< kBlockSize >::Get | ( | const GoogleString & | key, |
Callback * | callback | ||
) | [virtual] |
Initiates a cache fetch, calling callback->ValidateCandidate() and then callback->Done(state) when done.
Note: implementations should normally invoke the callback via ValidateAndReportResult, which will combine ValidateCandidate() and Done() together properly.
Implements net_instaweb::CacheInterface.
static void net_instaweb::SharedMemCache< kBlockSize >::GlobalCleanup | ( | AbstractSharedMem * | shm_runtime, |
const GoogleString & | filename, | ||
MessageHandler * | message_handler | ||
) | [static] |
This should be called from the root process as it is about to exit, when no further children are expected to start.
bool net_instaweb::SharedMemCache< kBlockSize >::Initialize | ( | ) |
Sets up our shared state for use of all child processes/threads. Returns whether successful. This should be called exactly once for every cache in the root process, before forking.
virtual bool net_instaweb::SharedMemCache< kBlockSize >::IsBlocking | ( | ) | const [inline, virtual] |
Returns true if this cache is guaranteed to call its callbacks before returning from Get and MultiGet.
Implements net_instaweb::CacheInterface.
virtual bool net_instaweb::SharedMemCache< kBlockSize >::IsHealthy | ( | ) | const [inline, virtual] |
Returns true if the cache is in a healthy state. Memory and file-based caches can simply return 'true'. But for server-based caches, it is handy to be able to query to see whether it is in a good state. It should be safe to call this frequently -- the implementation shouldn't do much more than check a bool flag under mutex.
Implements net_instaweb::CacheInterface.
virtual void net_instaweb::SharedMemCache< kBlockSize >::Put | ( | const GoogleString & | key, |
SharedString * | value | ||
) | [virtual] |
Puts a value into the cache. The value that is passed in is not modified, but the SharedString is passed by non-const pointer because its reference count is bumped.
Implements net_instaweb::CacheInterface.
virtual void net_instaweb::SharedMemCache< kBlockSize >::ShutDown | ( | ) | [inline, virtual] |
Stops all cache activity. Further Put/Delete calls will be dropped, and MultiGet/Get will call the callback with kNotFound immediately. Note there is no Enable(); once the cache is stopped it is stopped forever. This function is intended for use during process shutdown.
Implements net_instaweb::CacheInterface.
const int net_instaweb::SharedMemCache< kBlockSize >::kAssociativity = 4 [static] |
Note: changing this requires changing