92 #ifndef NET_INSTAWEB_UTIL_PUBLIC_PROPERTY_CACHE_H_
93 #define NET_INSTAWEB_UTIL_PUBLIC_PROPERTY_CACHE_H_
100 #include "net/instaweb/util/public/cache_interface.h"
101 #include "net/instaweb/util/public/ref_counted_ptr.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_;
176 DISALLOW_COPY_AND_ASSIGN(PropertyValue);
188 explicit Cohort(StringPiece name) {
189 name.CopyToString(&name_);
191 const GoogleString& name()
const {
return name_; }
196 DISALLOW_COPY_AND_ASSIGN(
Cohort);
199 typedef std::vector<const Cohort*> CohortVector;
206 ThreadSystem* threads);
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;
260 Statistics* statistics);
263 static GoogleString
GetStatsPrefix(
const GoogleString& cohort_name);
266 Timer*
timer()
const {
return timer_; }
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 kDevicePropertyCachePage,
351 const StringPiece& property_name);
357 const StringPiece& value);
376 CacheInterface::KeyState x);
388 const StringPiece& property_name);
391 return request_context_->log_record();
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);
431 StringPiece options_signature_hash,
432 StringPiece cache_key_suffix,
433 const RequestContextPtr& request_context,
434 AbstractMutex* mutex,
438 virtual void Done(
bool success) = 0;
441 void SetupCohorts(
const PropertyCache::CohortVector& cohort_list);
446 void CallDone(
bool success) {
451 typedef std::map<GoogleString, PropertyValue*> PropertyMap;
453 struct PropertyMapStruct {
454 explicit PropertyMapStruct(AbstractLogRecord* log)
455 : has_deleted_property(false),
459 bool has_deleted_property;
460 AbstractLogRecord* log_record;
461 CacheInterface::KeyState cache_state;
464 typedef std::map<const PropertyCache::Cohort*, PropertyMapStruct*>
466 CohortDataMap cohort_data_map_;
467 scoped_ptr<AbstractMutex> mutex_;
469 GoogleString options_signature_hash_;
470 GoogleString cache_key_suffix_;
471 RequestContextPtr request_context_;
473 PropertyCache* property_cache_;
474 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.
const CohortVector GetAllCohorts() const
Returns all the cohorts from cache.
Definition: property_cache.h:220
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:61
virtual PropertyValue * GetProperty(const PropertyCache::Cohort *cohort, const StringPiece &property_name)=0
Definition: property_cache.h:323
bool IsStable(int stable_hit_per_thousand_threshold) const
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
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
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
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.