Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
property_cache_util.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
21 
22 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_PROPERTY_CACHE_UTIL_H_
23 #define NET_INSTAWEB_REWRITER_PUBLIC_PROPERTY_CACHE_UTIL_H_
24 
27 #include "net/instaweb/util/public/property_cache.h"
33 
34 namespace net_instaweb {
35 
38  kPropertyCacheDecodeExpired,
39  kPropertyCacheDecodeParseError,
40  kPropertyCacheDecodeOk
41 };
42 
45 const PropertyValue* DecodeFromPropertyCacheHelper(
46  const PropertyCache* cache,
47  AbstractPropertyPage* page,
48  const PropertyCache::Cohort* cohort,
49  StringPiece property_name,
50  int64 cache_ttl_ms,
52 
60 template<typename T>
63  const PropertyCache::Cohort* cohort,
64  StringPiece property_name,
65  int64 cache_ttl_ms,
66  PropertyCacheDecodeResult* status) {
67  const PropertyValue* property_value =
68  DecodeFromPropertyCacheHelper(cache, page, cohort, property_name,
69  cache_ttl_ms, status);
70  if (property_value == NULL) {
72  return NULL;
73  }
74 
75  scoped_ptr<T> result(new T);
76  ArrayInputStream input(property_value->value().data(),
77  property_value->value().size());
78  if (!result->ParseFromZeroCopyStream(&input)) {
79  *status = kPropertyCacheDecodeParseError;
80  return NULL;
81  }
82 
83  *status = kPropertyCacheDecodeOk;
84  return result.release();
85 }
86 
89 template<typename T>
91  const PropertyCache::Cohort* cohort,
92  StringPiece property_name,
93  int64 cache_ttl_ms,
94  PropertyCacheDecodeResult* status) {
95  return DecodeFromPropertyCache<T>(
96  driver->server_context()->page_property_cache(),
97  driver->property_page(),
98  cohort,
99  property_name,
100  cache_ttl_ms,
101  status);
102 }
103 
106  kPropertyCacheUpdateEncodeError,
107  kPropertyCacheUpdateOk
108 };
109 
110 PropertyCacheUpdateResult UpdateInPropertyCache(
111  const protobuf::MessageLite& value,
112  const PropertyCache::Cohort* cohort,
113  StringPiece property_name,
114  bool write_cohort,
115  AbstractPropertyPage* page);
116 
121 inline PropertyCacheUpdateResult UpdateInPropertyCache(
122  const protobuf::MessageLite& value, RewriteDriver* driver,
123  const PropertyCache::Cohort* cohort, StringPiece property_name,
124  bool write_cohort) {
125  AbstractPropertyPage* page = driver->property_page();
126  return UpdateInPropertyCache(
127  value, cohort, property_name, write_cohort, page);
128 }
129 
130 }
131 
132 #endif
can't find existing value to update
Definition: property_cache_util.h:105
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 PropertyValue * DecodeFromPropertyCacheHelper(const PropertyCache *cache, AbstractPropertyPage *page, const PropertyCache::Cohort *cohort, StringPiece property_name, int64 cache_ttl_ms, PropertyCacheDecodeResult *status)
Definition: property_cache.h:186
Adds property-semantics to a raw cache API.
Definition: property_cache.h:180
PropertyCacheUpdateResult
Definition: property_cache_util.h:104
T * DecodeFromPropertyCache(const PropertyCache *cache, AbstractPropertyPage *page, const PropertyCache::Cohort *cohort, StringPiece property_name, int64 cache_ttl_ms, PropertyCacheDecodeResult *status)
Definition: property_cache_util.h:61
Definition: scoped_ptr.h:30
PropertyPage * property_page() const
includes property cache not being enabled.
Definition: property_cache_util.h:37
Definition: rewrite_driver.h:100
PropertyCacheDecodeResult
Definition: property_cache_util.h:36