Page Speed Optimization Libraries
1.2.24.1
|
Adds property-semantics to a raw cache API. More...
#include "property_cache.h"
Classes | |
class | Cohort |
Public Member Functions | |
PropertyCache (const GoogleString &cache_key_prefix, CacheInterface *cache, Timer *timer, ThreadSystem *threads) | |
void | Read (PropertyPage *property_page) const |
void | WriteCohort (const Cohort *cohort, PropertyPage *property_page) const |
bool | IsStable (const PropertyValue *property) const |
Determines whether a value that was read is reasonably stable. | |
bool | IsExpired (const PropertyValue *property_value, int64 ttl_ms) const |
bool | IsImminentlyExpiring (const PropertyValue *property_value, int64 ttl_ms) const |
Determines whether the value is expiring soon, and needs to be refreshed. | |
void | UpdateValue (const StringPiece &value, PropertyValue *property) const |
void | set_mutations_per_1000_writes_threshold (int x) |
const Cohort * | AddCohort (const StringPiece &cohort_name) |
Establishes a new Cohort for this property cache. | |
const Cohort * | GetCohort (const StringPiece &cohort_name) const |
void | set_enabled (bool x) |
bool | enabled () const |
Indicates if the property cache is enabled. | |
GoogleString | CacheKey (const StringPiece &key, const Cohort *cohort) const |
const CacheInterface * | cache_backend () const |
Static Public Attributes | |
static const char | kPagePropertyCacheKeyPrefix [] |
Property cache key prefixes. | |
static const char | kClientPropertyCacheKeyPrefix [] |
Adds property-semantics to a raw cache API.
GoogleString net_instaweb::PropertyCache::CacheKey | ( | const StringPiece & | key, |
const Cohort * | cohort | ||
) | const |
Gets the underlying key associated with cache_key and a Cohort. This is the key used for the CacheInterface provided to the constructor. This is made visible for testing, to make it possible to inject delays into the cache via DelayCache::DelayKey.
const Cohort* net_instaweb::PropertyCache::GetCohort | ( | const StringPiece & | cohort_name | ) | const |
Returns the specified Cohort* or NULL if not found. Cohorts must be established at startup time, via AddCohort before any pages are processed via Read & Write.
bool net_instaweb::PropertyCache::IsExpired | ( | const PropertyValue * | property_value, |
int64 | ttl_ms | ||
) | const |
Determines whether a value is expired relative to the specified TTL.
It is an error (DCHECK) to call this method when !property->has_value().
Note; we could also store the TTL in the cache-value itself. That would be useful if we derived the TTL from the data or other transients. But our envisioned usage has the TTL coming from a configuration that is available at read-time, so for now we just use that.
void net_instaweb::PropertyCache::Read | ( | PropertyPage * | property_page | ) | const |
Reads the all the PropertyValues in all the known Cohorts from cache, calling PropertyPage::Done when done. It is essential that the Cohorts are established prior to calling this function.
void net_instaweb::PropertyCache::set_enabled | ( | bool | x | ) | [inline] |
Allows turning off all reads/writes with a switch. Writes to a disabled cache are ignored. Reads cause Done(false) to be called immediately.
void net_instaweb::PropertyCache::UpdateValue | ( | const StringPiece & | value, |
PropertyValue * | property | ||
) | const |
Updates the value of a property, tracking stability & discarding writes when the existing data is more up-to-date.
void net_instaweb::PropertyCache::WriteCohort | ( | const Cohort * | cohort, |
PropertyPage * | property_page | ||
) | const |
Updates a Cohort of properties into the cache. It is a programming error (dcheck-fail) to Write a PropertyPage that was not read first. It is fine to Write after a failed Read.
Even if a PropertyValue was not changed since it was read, Write should be called periodically to update stability metrics.