Page Speed Optimization Libraries
1.5.27.2
|
#include "cache_stats.h"
Public Member Functions | |
CacheStats (StringPiece prefix, CacheInterface *cache, Timer *timer, Statistics *statistics) | |
Doees not takes ownership of the cache, timer, or statistics. | |
virtual void | Get (const GoogleString &key, Callback *callback) |
virtual void | MultiGet (MultiGetRequest *request) |
virtual void | Put (const GoogleString &key, SharedString *value) |
virtual void | Delete (const GoogleString &key) |
virtual CacheInterface * | Backend () |
virtual bool | IsBlocking () const |
virtual bool | IsHealthy () const |
virtual void | ShutDown () |
virtual GoogleString | Name () const |
Static Public Member Functions | |
static void | InitStats (StringPiece prefix, Statistics *statistics) |
This must be called once for every unique cache prefix. | |
static GoogleString | FormatName (StringPiece prefix, StringPiece cache) |
Friends | |
class | StatsCallback |
Wrapper around a CacheInterface that adds statistics and histograms for hit-rate, latency, etc. As there can be multiple caches in a system (l1, l2, etc), the constructor takes a string prefix so they can be measured independently.
virtual CacheInterface* net_instaweb::CacheStats::Backend | ( | ) | [inline, 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 from net_instaweb::CacheInterface.
virtual void net_instaweb::CacheStats::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::CacheStats::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.
virtual bool net_instaweb::CacheStats::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.
virtual void net_instaweb::CacheStats::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::CacheStats::Name | ( | ) | const [inline, 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.
Implements net_instaweb::CacheInterface.
virtual void net_instaweb::CacheStats::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.
virtual void net_instaweb::CacheStats::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.
Implements net_instaweb::CacheInterface.