92 #ifndef PAGESPEED_OPT_HTTP_PROPERTY_CACHE_H_
93 #define PAGESPEED_OPT_HTTP_PROPERTY_CACHE_H_
103 #include "pagespeed/kernel/cache/cache_interface.h"
106 namespace net_instaweb {
108 class AbstractLogRecord;
110 class AbstractPropertyStoreGetCallback;
111 class PropertyCacheValues;
112 class PropertyValueProtobuf;
119 typedef std::vector<PropertyPage*> PropertyPageStarVector;
124 StringPiece value()
const;
125 bool has_value()
const {
return valid_; }
138 bool IsStable(
int stable_hit_per_thousand_threshold)
const;
159 void InitFromProtobuf(
const PropertyValueProtobuf& value);
167 void SetValue(
const StringPiece& value, int64 now_ms);
169 PropertyValueProtobuf* protobuf() {
return proto_.get(); }
171 scoped_ptr<PropertyValueProtobuf> proto_;
188 explicit Cohort(StringPiece name) {
189 name.CopyToString(&name_);
199 typedef std::vector<const Cohort*> CohortVector;
224 return property->IsStable(mutations_per_1000_writes_threshold_);
237 void set_mutations_per_1000_writes_threshold(
int x) {
238 mutations_per_1000_writes_threshold_ = x;
243 const Cohort*
AddCohort(
const StringPiece& cohort_name);
248 const Cohort*
GetCohort(
const StringPiece& cohort_name)
const;
268 ThreadSystem* thread_system()
const {
return thread_system_; }
270 PropertyStore* property_store() {
return property_store_; }
275 PropertyStore* property_store_;
278 ThreadSystem* thread_system_;
280 int mutations_per_1000_writes_threshold_;
281 typedef std::map<GoogleString, Cohort*> CohortMap;
284 CohortVector cohort_list_;
298 const StringPiece& property_name) = 0;
304 const StringPiece& value) = 0;
317 const StringPiece& property_name) = 0;
328 kPropertyCacheFallbackPage,
329 kPropertyCachePerOriginPage,
351 const StringPiece& property_name);
357 const StringPiece& value);
388 const StringPiece& property_name);
395 void Read(
const PropertyCache::CohortVector& cohort_list);
402 virtual bool IsCacheValid(int64 write_timestamp_ms)
const {
return true; }
406 const PropertyValueProtobuf& proto);
423 PropertyCacheValues* values);
434 StringPiece options_signature_hash,
435 StringPiece cache_key_suffix,
441 virtual void Done(
bool success) = 0;
444 void SetupCohorts(
const PropertyCache::CohortVector& cohort_list);
449 void CallDone(
bool success) {
454 typedef std::map<GoogleString, PropertyValue*> PropertyMap;
456 struct PropertyMapStruct {
457 explicit PropertyMapStruct(AbstractLogRecord* log)
458 : has_deleted_property(false),
462 bool has_deleted_property;
463 AbstractLogRecord* log_record;
467 typedef std::map<const PropertyCache::Cohort*, PropertyMapStruct*>
469 CohortDataMap cohort_data_map_;
470 scoped_ptr<AbstractMutex> mutex_;
474 RequestContextPtr request_context_;
476 PropertyCache* property_cache_;
477 AbstractPropertyStoreGetCallback* property_store_callback_;
Abstract interface for implementing a PropertyPage.
Definition: property_cache.h:291
Holds the value & stability-metadata for a property.
Definition: property_cache.h:122
const Cohort * GetCohort(const StringPiece &cohort_name) const
Definition: property_cache.h:186
void Abort()
Abort the reading of PropertyPage.
PropertyCache(PropertyStore *property_store, Timer *timer, Statistics *stats, ThreadSystem *threads)
Adds property-semantics to a raw cache API.
Definition: property_cache.h:180
Definition: property_store.h:41
bool IsRecentlyConstant(int num_writes_unchanged) const
bool IsCohortPresent(const PropertyCache::Cohort *cohort)
Returns true if cohort present in the PropertyPage.
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
Abstract interface for implementing a mutex.
Definition: abstract_mutex.h:28
int64 write_timestamp_ms() const
PropertyPage(PageType page_type, StringPiece url, StringPiece options_signature_hash, StringPiece cache_key_suffix, const RequestContextPtr &request_context, AbstractMutex *mutex, PropertyCache *property_cache)
void Read(const PropertyCache::CohortVector &cohort_list)
Read the property page from cache.
Definition: log_record.h:59
virtual PropertyValue * GetProperty(const PropertyCache::Cohort *cohort, const StringPiece &property_name)=0
Definition: property_cache.h:323
KeyState
Definition: cache_interface.h:34
const CohortVector & GetAllCohorts() const
Returns all the cohorts from cache.
Definition: property_cache.h:220
bool IsStable(int stable_hit_per_thousand_threshold) const
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
bool IsStable(const PropertyValue *property) const
Determines whether a value that was read is reasonably stable.
Definition: property_cache.h:223
PageType
The cache type associated with this callback.
Definition: property_cache.h:326
virtual AbstractLogRecord * log_record()
The log record for the this request, created when the request context is.
void SetCacheState(const PropertyCache::Cohort *cohort, CacheInterface::KeyState x)
void Read(PropertyPage *property_page) const
void DeleteProperty(const PropertyCache::Cohort *cohort, const StringPiece &property_name)
virtual void Done(bool success)=0
Called as a result of PropertyCache::Read when the data is available.
bool IsExpired(const PropertyValue *property_value, int64 ttl_ms) const
PageType page_type()
Returns the type of the page.
Definition: property_cache.h:409
Timer * timer() const
Returns timer pointer.
Definition: property_cache.h:266
bool EncodePropertyCacheValues(const PropertyCache::Cohort *cohort, PropertyCacheValues *values)
const Cohort * AddCohort(const StringPiece &cohort_name)
static void InitCohortStats(const GoogleString &cohort, Statistics *statistics)
Initialize stats for the specified cohort.
static bool IsIndexOfLeastSetBitSmaller(uint64 value, int index)
bool enabled() const
Indicates if the property cache is enabled.
Definition: property_cache.h:256
Definition: thread_system.h:40
virtual CacheInterface::KeyState GetCacheState(const PropertyCache::Cohort *cohort)=0
This function returns the cache state for a given cohort.
CacheInterface::KeyState GetCacheState(const PropertyCache::Cohort *cohort)
virtual void UpdateValue(const PropertyCache::Cohort *cohort, const StringPiece &property_name, const StringPiece &value)=0
void set_enabled(bool x)
Definition: property_cache.h:253
bool was_read()
Definition: property_cache.h:133
virtual void WriteCohort(const PropertyCache::Cohort *cohort)=0
void ReadWithCohorts(const CohortVector &cohort_list, PropertyPage *property_page) const
virtual void WriteCohort(const PropertyCache::Cohort *cohort)
virtual bool IsCacheValid(int64 write_timestamp_ms) const
Definition: property_cache.h:402
static StringPiece PageTypeSuffix(PageType type)
Suffix for property cache keys for given page type.
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
void AddValueFromProtobuf(const PropertyCache::Cohort *cohort, const PropertyValueProtobuf &proto)
Populate PropertyCacheValues to the respective cohort in PropertyPage.
virtual void DeleteProperty(const PropertyCache::Cohort *cohort, const StringPiece &property_name)=0
Deletes a property given the property name.
virtual void UpdateValue(const PropertyCache::Cohort *cohort, const StringPiece &property_name, const StringPiece &value)
virtual PropertyValue * GetProperty(const PropertyCache::Cohort *cohort, const StringPiece &property_name)
static GoogleString GetStatsPrefix(const GoogleString &cohort_name)
Creates stats prefix for the given cohort.