Page Speed Optimization Libraries
1.3.25.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, Statistics *stats, ThreadSystem *threads) | |
void | Read (PropertyPage *property_page) const |
void | ReadWithCohorts (PropertyPage *property_page, const StringVector cohort_names) const |
void | MultiRead (PropertyPageStarVector *property_page_list) const |
void | MultiReadWithCohorts (PropertyPageStarVector *property_page_list, const StringVector cohort_name_list) const |
void | SetupCohorts (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 |
void | UpdateValue (const StringPiece &value, PropertyValue *property) const |
void | set_mutations_per_1000_writes_threshold (int x) |
const Cohort * | AddCohort (const StringPiece &cohort_name) |
const Cohort * | AddCohortWithCache (const StringPiece &cohort_name, CacheInterface *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 Member Functions | |
static void | InitCohortStats (const GoogleString &cohort, Statistics *statistics) |
Initialize stats for the specified cohort. | |
Static Public Attributes | |
static const char | kPagePropertyCacheKeyPrefix [] |
Property cache key prefixes. | |
static const char | kClientPropertyCacheKeyPrefix [] |
static const char | kDevicePropertyCacheKeyPrefix [] |
Adds property-semantics to a raw cache API.
const Cohort* net_instaweb::PropertyCache::AddCohort | ( | const StringPiece & | cohort_name | ) |
Establishes a new Cohort for this property cache backed by the CacheInteface passed to the constructor. Note that you must call InitCohortStats prior to calling AddCohort.
const Cohort* net_instaweb::PropertyCache::AddCohortWithCache | ( | const StringPiece & | cohort_name, |
CacheInterface * | cache | ||
) |
Establishes a new Cohort to be backed by the specified CacheInterface. NOTE: Does not take ownership of the CacheInterface object.
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::MultiRead | ( | PropertyPageStarVector * | property_page_list | ) | const |
Reads PropertyValues for multiple pages, calling corresponding PropertyPage::Done as and when page read completes. It is essential that the Cohorts are established prior to calling this function.
void net_instaweb::PropertyCache::MultiReadWithCohorts | ( | PropertyPageStarVector * | property_page_list, |
const StringVector | cohort_name_list | ||
) | const |
Reads PropertyValues for multiple pages, each page has a specified cohorts. Here all pages from property_page_list have the same cohort list. Notes: Maybe PropertyPageStarVector should contain specified cohort information.
void net_instaweb::PropertyCache::Read | ( | PropertyPage * | property_page | ) | const |
Reads 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::ReadWithCohorts | ( | PropertyPage * | property_page, |
const StringVector | cohort_names | ||
) | const |
Reads all the PropertyValues in the specified Cohorts from cache, calling PropertyPage::Done when done.
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.