Page Speed Optimization Libraries
1.5.27.2
|
Abstract interface for a cache. More...
#include "cache_interface.h"
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< KeyCallback > | MultiGetRequest |
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 GoogleString | Name () const =0 |
virtual CacheInterface * | Backend () |
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) |
Abstract interface for a cache.
virtual CacheInterface* net_instaweb::CacheInterface::Backend | ( | ) | [virtual] |
If this cache is merely a wrapper around a backend that actually does all the work, returns that backend cache object. Otherwise just returns 'this'. Used for testing.
Reimplemented in net_instaweb::CacheStats, net_instaweb::ThreadsafeCache, and net_instaweb::CompressedCache.
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::CompressedCache.
virtual bool net_instaweb::CacheInterface::IsBlocking | ( | ) | const [pure virtual] |
Returns true if this cache is guaranteed to call its callbacks before returning from Get and MultiGet.
Implemented in net_instaweb::SharedMemCache< kBlockSize >, net_instaweb::AprMemCache, net_instaweb::LRUCache, net_instaweb::CacheBatcher, net_instaweb::DelayCache, net_instaweb::AsyncCache, net_instaweb::FileCache, net_instaweb::MockTimeCache, net_instaweb::WriteThroughCache, net_instaweb::CacheStats, net_instaweb::FallbackCache, net_instaweb::ThreadsafeCache, and net_instaweb::CompressedCache.
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::FallbackCache, net_instaweb::CacheStats, net_instaweb::ThreadsafeCache, and net_instaweb::CompressedCache.
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, and net_instaweb::FallbackCache.
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 GoogleString net_instaweb::CacheInterface::Name | ( | ) | const [pure virtual] |
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 net/instaweb/system/system_caches_test.cc.
Implemented in net_instaweb::SharedMemCache< kBlockSize >, net_instaweb::AprMemCache, net_instaweb::LRUCache, net_instaweb::CacheBatcher, net_instaweb::DelayCache, net_instaweb::WriteThroughCache, net_instaweb::AsyncCache, net_instaweb::FallbackCache, net_instaweb::FileCache, net_instaweb::CacheStats, net_instaweb::MockTimeCache, net_instaweb::ThreadsafeCache, and net_instaweb::CompressedCache.
virtual void net_instaweb::CacheInterface::Put | ( | const GoogleString & | key, |
SharedString * | value | ||
) | [pure 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.
Implemented in net_instaweb::SharedMemCache< kBlockSize >, net_instaweb::AprMemCache, net_instaweb::CacheBatcher, net_instaweb::AsyncCache, net_instaweb::FileCache, net_instaweb::LRUCache, net_instaweb::DelayCache, net_instaweb::CacheStats, net_instaweb::FallbackCache, net_instaweb::MockTimeCache, net_instaweb::ThreadsafeCache, net_instaweb::WriteThroughCache, and net_instaweb::CompressedCache.
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::FileCache, net_instaweb::WriteThroughCache, net_instaweb::FallbackCache, net_instaweb::MockTimeCache, net_instaweb::CacheStats, net_instaweb::ThreadsafeCache, and net_instaweb::CompressedCache.