Page Speed Optimization Libraries
1.13.35.1
|
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, const 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, const SharedString &key_and_value) |
Static Public Member Functions | |
static const char * | KeyStateName (KeyState state) |
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 |
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, net_instaweb::CompressedCache, and net_instaweb::CacheKeyPrepender.
|
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::RedisCache, net_instaweb::CacheBatcher, net_instaweb::AprMemCache, net_instaweb::FileCache, net_instaweb::AsyncCache, net_instaweb::DelayCache, net_instaweb::CacheStats, net_instaweb::FallbackCache, net_instaweb::ThreadsafeCache, net_instaweb::LRUCache, net_instaweb::MockTimeCache, net_instaweb::InMemoryCache, net_instaweb::WriteThroughCache, net_instaweb::CompressedCache, and net_instaweb::CacheKeyPrepender.
|
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::CacheBatcher, net_instaweb::AprMemCache, net_instaweb::LRUCache, net_instaweb::RedisCache, net_instaweb::DelayCache, net_instaweb::FileCache, net_instaweb::AsyncCache, net_instaweb::MockTimeCache, net_instaweb::WriteThroughCache, net_instaweb::CacheStats, net_instaweb::FallbackCache, net_instaweb::ThreadsafeCache, net_instaweb::InMemoryCache, net_instaweb::CompressedCache, and net_instaweb::CacheKeyPrepender.
|
pure virtual |
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.
Implemented in net_instaweb::SharedMemCache< kBlockSize >, net_instaweb::AprMemCache, net_instaweb::CacheBatcher, net_instaweb::LRUCache, net_instaweb::RedisCache, net_instaweb::AsyncCache, net_instaweb::DelayCache, net_instaweb::FileCache, net_instaweb::WriteThroughCache, net_instaweb::MockTimeCache, net_instaweb::FallbackCache, net_instaweb::CacheStats, net_instaweb::ThreadsafeCache, net_instaweb::InMemoryCache, net_instaweb::CompressedCache, and net_instaweb::CacheKeyPrepender.
|
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::FallbackCache, net_instaweb::CacheStats, and net_instaweb::CacheKeyPrepender.
|
inlinevirtual |
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.
|
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 third_party/pagespeed/system/system_caches_test.cc.
Implemented in net_instaweb::SharedMemCache< kBlockSize >, net_instaweb::CacheBatcher, net_instaweb::AprMemCache, net_instaweb::LRUCache, net_instaweb::RedisCache, net_instaweb::DelayCache, net_instaweb::FileCache, net_instaweb::WriteThroughCache, net_instaweb::FallbackCache, net_instaweb::AsyncCache, net_instaweb::CacheStats, net_instaweb::MockTimeCache, net_instaweb::ThreadsafeCache, net_instaweb::CacheKeyPrepender, net_instaweb::InMemoryCache, and net_instaweb::CompressedCache.
|
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::RedisCache, net_instaweb::CacheBatcher, net_instaweb::AprMemCache, net_instaweb::FileCache, net_instaweb::AsyncCache, net_instaweb::LRUCache, net_instaweb::DelayCache, net_instaweb::CacheStats, net_instaweb::FallbackCache, net_instaweb::ThreadsafeCache, net_instaweb::MockTimeCache, net_instaweb::InMemoryCache, net_instaweb::WriteThroughCache, net_instaweb::CompressedCache, and net_instaweb::CacheKeyPrepender.
|
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.
|
inlinevirtual |
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.
|
protected |
Helper method to report a NotFound on each MultiGet key. Deletes the request.
|
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::SharedMemCache< kBlockSize >, net_instaweb::AprMemCache, net_instaweb::CacheBatcher, net_instaweb::LRUCache, net_instaweb::RedisCache, net_instaweb::AsyncCache, net_instaweb::DelayCache, net_instaweb::FileCache, net_instaweb::WriteThroughCache, net_instaweb::FallbackCache, net_instaweb::MockTimeCache, net_instaweb::CacheStats, net_instaweb::ThreadsafeCache, net_instaweb::InMemoryCache, net_instaweb::CompressedCache, and net_instaweb::CacheKeyPrepender.