Page Speed Optimization Libraries  1.3.25.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Types | Public Member Functions | Protected Member Functions
net_instaweb::CacheInterface Class Reference

Abstract interface for a cache. More...

#include "cache_interface.h"

Inheritance diagram for net_instaweb::CacheInterface:
net_instaweb::AprMemCache net_instaweb::AsyncCache net_instaweb::CacheBatcher net_instaweb::CacheCopy net_instaweb::CacheStats net_instaweb::DelayCache net_instaweb::FallbackCache net_instaweb::FileCache net_instaweb::LRUCache net_instaweb::MockTimeCache net_instaweb::SharedMemCache< kBlockSize > net_instaweb::ThreadsafeCache net_instaweb::WriteThroughCache

List of all members.

Classes

class  Callback
struct  KeyCallback
 Vector of structures used to initiate a MultiGet. More...
class  SynchronousCallback

Public Types

enum  KeyState {
  kAvailable = 0, kNotFound = 1, kOverload = 2, kNetworkError = 3,
  kTimeout = 4
}
typedef std::vector< KeyCallbackMultiGetRequest

Public Member Functions

virtual void Get (const GoogleString &key, Callback *callback)=0
virtual void MultiGet (MultiGetRequest *request)
virtual void Put (const GoogleString &key, SharedString *value)=0
virtual void Delete (const GoogleString &key)=0
void PutSwappingString (const GoogleString &key, GoogleString *value)
virtual const char * Name () const =0
 The name of this CacheInterface -- used for logging and debugging.
virtual bool IsBlocking () const =0
virtual bool IsHealthy () const =0
virtual void ShutDown ()=0
virtual bool MustEncodeKeyInValueOnPut () const
virtual void PutWithKeyInValue (const GoogleString &key, SharedString *key_and_value)

Protected Member Functions

void ValidateAndReportResult (const GoogleString &key, KeyState state, Callback *callback)
 Invokes callback->ValidateCandidate() and callback->Done() as appropriate.
void ReportMultiGetNotFound (MultiGetRequest *request)

Detailed Description

Abstract interface for a cache.


Member Enumeration Documentation

Enumerator:
kAvailable 

Requested key is available for serving.

kNotFound 

Requested key needs to be written.

kOverload 

Lookup is discarded due to cache server is overloaded.

kNetworkError 

Cache lookup ended up in network error.

kTimeout 

Request timeout.


Member Function Documentation

virtual void net_instaweb::CacheInterface::Get ( const GoogleString key,
Callback callback 
) [pure 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.

Implemented in net_instaweb::SharedMemCache< kBlockSize >, net_instaweb::AprMemCache, net_instaweb::CacheBatcher, net_instaweb::AsyncCache, net_instaweb::FileCache, net_instaweb::DelayCache, net_instaweb::LRUCache, net_instaweb::CacheStats, net_instaweb::FallbackCache, net_instaweb::MockTimeCache, net_instaweb::ThreadsafeCache, net_instaweb::WriteThroughCache, and net_instaweb::CacheCopy.

virtual bool net_instaweb::CacheInterface::IsBlocking ( ) const [pure virtual]
virtual bool net_instaweb::CacheInterface::IsHealthy ( ) const [pure 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.

Implemented in net_instaweb::AprMemCache, net_instaweb::SharedMemCache< kBlockSize >, net_instaweb::CacheBatcher, net_instaweb::LRUCache, net_instaweb::AsyncCache, net_instaweb::DelayCache, net_instaweb::FileCache, net_instaweb::WriteThroughCache, net_instaweb::MockTimeCache, net_instaweb::CacheStats, net_instaweb::FallbackCache, net_instaweb::ThreadsafeCache, and net_instaweb::CacheCopy.

virtual void net_instaweb::CacheInterface::MultiGet ( MultiGetRequest *  request) [virtual]

Gets multiple keys, calling multiple callbacks. Default implementation simply loops over all the keys and calls Get.

MultiGetRequest, declared above, is a vector of structs of keys and callbacks.

Ownership of the request is transferred to this function.

Reimplemented in net_instaweb::AprMemCache, net_instaweb::AsyncCache, net_instaweb::DelayCache, net_instaweb::CacheStats, net_instaweb::FallbackCache, and net_instaweb::CacheCopy.

virtual bool net_instaweb::CacheInterface::MustEncodeKeyInValueOnPut ( ) const [inline, virtual]

To deal with underlying cache systems (e.g. memcached) that cannot tolerate arbitrary-sized keys, we use a hash of the key and put the key in the value, using the functions in key_value_codec.h.

To do this without pointlessly copying the value bytes, we use SharedString::Append(). However, that's not thread-safe. So when making a cache Asynchronous with AsyncCache, we must do the SharedString::Append call in the thread that initiates the Put, before queuing a threaded Put.

This method indicates whether a cache implementation requires encoding the keys in the value using key_value_codec.

Reimplemented in net_instaweb::AprMemCache.

virtual void net_instaweb::CacheInterface::Put ( const GoogleString key,
SharedString value 
) [pure virtual]
void net_instaweb::CacheInterface::PutSwappingString ( const GoogleString key,
GoogleString value 
) [inline]

Convenience method to do a Put from a GoogleString* value. The bytes will be swapped out of the value and into a temp SharedString.

virtual void net_instaweb::CacheInterface::PutWithKeyInValue ( const GoogleString key,
SharedString key_and_value 
) [inline, virtual]

Performs a cache Put, but assumes the key has already been encoded into the value with key_value_codec. It is only valid to call this when MustEncodeKeyInValueOnPut() returns true.

Reimplemented in net_instaweb::AprMemCache.

void net_instaweb::CacheInterface::ReportMultiGetNotFound ( MultiGetRequest *  request) [protected]

Helper method to report a NotFound on each MultiGet key. Deletes the request.

virtual void net_instaweb::CacheInterface::ShutDown ( ) [pure 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.

Implemented in net_instaweb::AprMemCache, net_instaweb::SharedMemCache< kBlockSize >, net_instaweb::CacheBatcher, net_instaweb::LRUCache, net_instaweb::AsyncCache, net_instaweb::DelayCache, net_instaweb::WriteThroughCache, net_instaweb::FileCache, net_instaweb::FallbackCache, net_instaweb::CacheStats, net_instaweb::MockTimeCache, net_instaweb::ThreadsafeCache, and net_instaweb::CacheCopy.


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