Page Speed Optimization Libraries
1.4.26.1
|
#include "lru_cache.h"
Public Member Functions | |
LRUCache (size_t max_size) | |
virtual void | Get (const GoogleString &key, Callback *callback) |
virtual void | Put (const GoogleString &key, SharedString *new_value) |
virtual void | Delete (const GoogleString &key) |
size_t | size_bytes () const |
Total size in bytes of keys and values stored. | |
size_t | max_bytes_in_cache () const |
Maximum capacity. | |
size_t | num_elements () const |
Number of elements stored. | |
size_t | num_evictions () const |
size_t | num_hits () const |
size_t | num_misses () const |
size_t | num_inserts () const |
size_t | num_identical_reinserts () const |
size_t | num_deletes () const |
void | SanityCheck () |
Sanity check the cache data structures. | |
void | Clear () |
void | ClearStats () |
Clear the stats -- note that this will not clear the content. | |
virtual const char * | Name () const |
The name of this CacheInterface -- used for logging and debugging. | |
virtual bool | IsBlocking () const |
virtual bool | IsHealthy () const |
virtual void | ShutDown () |
void | set_is_healthy (bool x) |
Simple C++ implementation of an in-memory least-recently used (LRU) cache. This implementation is not thread-safe, and must be combined with a mutex to make it so.
The purpose of this implementation is as a default implementation, or an local shadow for memcached.
Also of note: the Get interface allows for streaming. To get into a GoogleString, use a StringWriter.
void net_instaweb::LRUCache::Clear | ( | ) |
Clear the entire cache. Used primarily for testing. Note that this will not clear the stats, however it will update current_bytes_in_cache_.
virtual void net_instaweb::LRUCache::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::LRUCache::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::LRUCache::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::LRUCache::Put | ( | const GoogleString & | key, |
SharedString * | new_value | ||
) | [virtual] |
Puts an object into the cache, sharing the bytes.
Implements net_instaweb::CacheInterface.
virtual void net_instaweb::LRUCache::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.