net_instaweb::LRUCache Class Reference

#include "lru_cache.h"

Inheritance diagram for net_instaweb::LRUCache:
net_instaweb::CacheInterface

List of all members.

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 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.

Detailed Description

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.

Todo:
TODO(jmarantz): The Put interface does not currently stream, but this should be added.

Member Function Documentation

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 void net_instaweb::LRUCache::Put ( const GoogleString key,
SharedString new_value 
) [virtual]

Puts an object into the cache, sharing the bytes.

Todo:
TODO(jmarantz): currently if the caller mutates the SharedString after having called Put, it will actually modify the value in the cache. We should change SharedString to Copy-On-Write semantics.

Implements net_instaweb::CacheInterface.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Tue May 29 16:34:11 2012 for Page Speed Optimization Libraries by  doxygen 1.6.3