Page Speed Optimization Libraries  1.4.26.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes
net_instaweb::SharedMemCache< kBlockSize > Class Template Reference

namespace SharedMemCacheData More...

#include "shared_mem_cache.h"

Inheritance diagram for net_instaweb::SharedMemCache< kBlockSize >:
net_instaweb::CacheInterface

List of all members.

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

Detailed Description

template<size_t kBlockSize>
class net_instaweb::SharedMemCache< kBlockSize >

namespace SharedMemCacheData

Abstract interface for a cache.


Constructor & Destructor Documentation

template<size_t kBlockSize>
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.


Member Function Documentation

template<size_t kBlockSize>
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.

template<size_t kBlockSize>
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.

template<size_t kBlockSize>
GoogleString net_instaweb::SharedMemCache< kBlockSize >::DumpStats ( )

Returns some statistics as plaintext.

Todo:
TODO(morlovich): Potentially periodically push these to the main Statistics system (or pull to it from these).
template<size_t kBlockSize>
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.

template<size_t kBlockSize>
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.

template<size_t kBlockSize>
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.

template<size_t kBlockSize>
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.

template<size_t kBlockSize>
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.

template<size_t kBlockSize>
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.

template<size_t kBlockSize>
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.

Todo:
TODO(morlovich): Implement

Implements net_instaweb::CacheInterface.


Member Data Documentation

template<size_t kBlockSize>
const int net_instaweb::SharedMemCache< kBlockSize >::kAssociativity = 4 [static]

Note: changing this requires changing


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines