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

Simple C++ implementation of file cache. More...

#include "file_cache.h"

Inheritance diagram for net_instaweb::FileCache:
net_instaweb::CacheInterface

Classes

struct  CachePolicy
 

Public Member Functions

 FileCache (const GoogleString &path, FileSystem *file_system, ThreadSystem *thread_system, SlowWorker *worker, CachePolicy *policy, Statistics *stats, 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)
 
void set_worker (SlowWorker *worker)
 
SlowWorkerworker ()
 
virtual GoogleString Name () const
 
virtual bool IsBlocking () const
 
virtual bool IsHealthy () const
 
virtual void ShutDown ()
 
const CachePolicycache_policy () const
 
CachePolicymutable_cache_policy ()
 
const GoogleStringpath () const
 
- Public Member Functions inherited from net_instaweb::CacheInterface
virtual void MultiGet (MultiGetRequest *request)
 
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 void InitStats (Statistics *statistics)
 
static GoogleString FormatName ()
 
- Static Public Member Functions inherited from net_instaweb::CacheInterface
static const char * KeyStateName (KeyState state)
 

Static Public Attributes

static const char kBytesFreedInCleanup []
 Variable names.
 
static const char kCleanups []
 Number of times we actually cleaned cache because usage was high enough.
 
static const char kDiskChecks []
 Number of times we checked disk usage in preparation from cleanup.
 
static const char kEvictions []
 Files evicted from cache during cleanup.
 
static const char kSkippedCleanups []
 
static const char kStartedCleanups []
 Number of times we scanned the cache to see if it needed cleaning.
 
static const char kWriteErrors []
 
static const int kDisableCleaning = -1
 

Friends

class FileCacheTest
 
class CacheCleanFunction
 

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

Simple C++ implementation of file cache.

Member Function Documentation

const CachePolicy* net_instaweb::FileCache::cache_policy ( ) const
inline
Todo:
TODO(jmarantz): implement.
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
inlinevirtual

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
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 GoogleString net_instaweb::FileCache::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::FileCache::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.

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

Member Data Documentation

const int net_instaweb::FileCache::kDisableCleaning = -1
static

What to set clean_interval_ms to in order to disable cleaning. This needs to be -1, because that's what we have in our public documentation.

const char net_instaweb::FileCache::kSkippedCleanups[]
static

Number of times we didn't kick off cleaning because a previous cleaning run was still going.


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