Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | List of all members
net_instaweb::FallbackCache Class Reference

#include "fallback_cache.h"

Inheritance diagram for net_instaweb::FallbackCache:
net_instaweb::CacheInterface

Public Member Functions

 FallbackCache (CacheInterface *small_object_cache, CacheInterface *large_object_cache, int threshold_bytes, MessageHandler *handler)
 
virtual void Get (const GoogleString &key, Callback *callback)
 
virtual void Put (const GoogleString &key, const SharedString &value)
 
virtual void Delete (const GoogleString &key)
 
virtual void MultiGet (MultiGetRequest *request)
 
virtual bool IsBlocking () const
 
virtual bool IsHealthy () const
 
virtual void ShutDown ()
 
virtual GoogleString Name () const
 
void set_account_for_key_size (bool x)
 
- Public Member Functions inherited from net_instaweb::CacheInterface
void PutSwappingString (const GoogleString &key, GoogleString *value)
 
virtual CacheInterfaceBackend ()
 
virtual bool MustEncodeKeyInValueOnPut () const
 
virtual void PutWithKeyInValue (const GoogleString &key, const SharedString &key_and_value)
 

Static Public Member Functions

static GoogleString FormatName (StringPiece small, StringPiece large)
 
- Static Public Member Functions inherited from net_instaweb::CacheInterface
static const char * KeyStateName (KeyState state)
 

Additional Inherited Members

- Public Types inherited from net_instaweb::CacheInterface
enum  KeyState {
  kAvailable = 0, kNotFound = 1, kOverload = 2, kNetworkError = 3,
  kTimeout = 4
}
 
typedef std::vector< KeyCallbackMultiGetRequest
 
- Protected Member Functions inherited from net_instaweb::CacheInterface
void ValidateAndReportResult (const GoogleString &key, KeyState state, Callback *callback)
 Invokes callback->ValidateCandidate() and callback->Done() as appropriate.
 
void ReportMultiGetNotFound (MultiGetRequest *request)
 

Detailed Description

Provides a mechanism to handle small objects with one cache, and large objects with another cache. This is not a write-through cache; the objects stored in small_object_cache are not stored in large_object_cache, though objects stored in large_object_cache require a flag in small_object_cache that guides Get to look in the large one.

Constructor & Destructor Documentation

net_instaweb::FallbackCache::FallbackCache ( CacheInterface small_object_cache,
CacheInterface large_object_cache,
int  threshold_bytes,
MessageHandler handler 
)

FallbackCache does not take ownership of either cache that's passed in.

The threshold is compared against the value-size + key size (default on, disable via set_account_for_key_size) on put. The threshold is inclusive: up to that many bytes will be stored into small_object_cache.

Member Function Documentation

virtual void net_instaweb::FallbackCache::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.

virtual bool net_instaweb::FallbackCache::IsBlocking ( ) const
inlinevirtual

Returns true if this cache is guaranteed to call its callbacks before returning from Get and MultiGet.

We can fulfill our guarantee only if both caches block.

Implements net_instaweb::CacheInterface.

virtual bool net_instaweb::FallbackCache::IsHealthy ( ) const
inlinevirtual

IsHealthy() is a rough estimation of whether cache is available for any operations. If it's false, caller may reasonably expect that making calls right now is useless as they will fail or have high latency. If it's true, operations should succeed, but some still may fail occasionally. The primary goal is to avoid sending commands to 'unhealthy' caches, e.g. if cache is under heavy load, we do not want to send even more requests.

Memory and file-based caches can simply return 'true'. It should be safe to call this frequently – the implementation shouldn't do much more that check a bool flag under mutex.

Implements net_instaweb::CacheInterface.

virtual void net_instaweb::FallbackCache::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 from net_instaweb::CacheInterface.

virtual GoogleString net_instaweb::FallbackCache::Name ( ) const
inlinevirtual

The name of this CacheInterface – used for logging and debugging.

It is strongly recommended that you provide a static GoogleString FormatName(...) method for use in formatting the Name() return, and in testing, e.g. in third_party/pagespeed/system/system_caches_test.cc.

Implements net_instaweb::CacheInterface.

virtual void net_instaweb::FallbackCache::Put ( const GoogleString key,
const 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.

void net_instaweb::FallbackCache::set_account_for_key_size ( bool  x)
inline

If true (the default) the space for the key will be added to the value size when checking whether a store exceeds threshold_bytes.

virtual void net_instaweb::FallbackCache::ShutDown ( )
inlinevirtual

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.


The documentation for this class was generated from the following file: