Page Speed Optimization Libraries
1.5.27.2
|
Simple C++ implementation of file cache. More...
#include "file_cache.h"
Classes | |
struct | CachePolicy |
Public Member Functions | |
FileCache (const GoogleString &path, FileSystem *file_system, SlowWorker *worker, FilenameEncoder *filename_encoder, CachePolicy *policy, Statistics *stats, MessageHandler *handler) | |
virtual void | Get (const GoogleString &key, Callback *callback) |
virtual void | Put (const GoogleString &key, SharedString *value) |
virtual void | Delete (const GoogleString &key) |
void | set_worker (SlowWorker *worker) |
SlowWorker * | worker () |
virtual GoogleString | Name () const |
virtual bool | IsBlocking () const |
virtual bool | IsHealthy () const |
virtual void | ShutDown () |
const CachePolicy * | cache_policy () const |
const GoogleString & | path () const |
Static Public Member Functions | |
static void | InitStats (Statistics *statistics) |
static GoogleString | FormatName () |
Static Public Attributes | |
static const char | kDiskChecks [] |
static const char | kCleanups [] |
Number of times we actually cleaned cache because usage was high enough. | |
static const char | kEvictions [] |
Files evicted from cache during cleanup. | |
static const char | kBytesFreedInCleanup [] |
Friends | |
class | FileCacheTest |
class | CacheCleanFunction |
Simple C++ implementation of file cache.
const CachePolicy* net_instaweb::FileCache::cache_policy | ( | ) | const [inline] |
virtual void net_instaweb::FileCache::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::FileCache::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::FileCache::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 GoogleString net_instaweb::FileCache::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::FileCache::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::FileCache::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.
const char net_instaweb::FileCache::kDiskChecks[] [static] |
Variable names. Number of times we checked disk usage in preparation from cleanup.