Page Speed Optimization Libraries
1.13.35.1
|
#include "apr_mem_cache.h"
Public Member Functions | |
AprMemCache (const ExternalClusterSpec &cluster, int thread_limit, Hasher *hasher, Statistics *statistics, Timer *timer, MessageHandler *handler) | |
const ExternalClusterSpec & | cluster_spec () const |
virtual void | Get (const GoogleString &key, Callback *callback) |
As mentioned above, Get and MultiGet are blocking in this implementation. | |
virtual void | Put (const GoogleString &key, const SharedString &value) |
virtual void | Delete (const GoogleString &key) |
virtual void | MultiGet (MultiGetRequest *request) |
bool | Connect () |
bool | valid_server_spec () const |
bool | GetStatus (GoogleString *status_string) |
virtual GoogleString | Name () const |
virtual bool | IsBlocking () const |
void | RecordError () |
virtual bool | IsHealthy () const |
virtual void | ShutDown () |
Close down the connection to the memcached servers. | |
virtual bool | MustEncodeKeyInValueOnPut () const |
virtual void | PutWithKeyInValue (const GoogleString &key, const SharedString &key_and_value) |
void | set_timeout_us (int timeout_us) |
Public Member Functions inherited from net_instaweb::CacheInterface | |
void | PutSwappingString (const GoogleString &key, GoogleString *value) |
virtual CacheInterface * | Backend () |
Static Public Member Functions | |
static void | InitStats (Statistics *statistics) |
static GoogleString | FormatName () |
Static Public Member Functions inherited from net_instaweb::CacheInterface | |
static const char * | KeyStateName (KeyState state) |
Static Public Attributes | |
static const size_t | kValueSizeThreshold = 1 * 1000 * 1000 |
static const int64 | kHealthCheckpointIntervalMs = 30 * Timer::kSecondMs |
Amount of time after a burst of errors to retry memcached operations. | |
static const int64 | kMaxErrorBurst = 4 |
Additional Inherited Members | |
Public Types inherited from net_instaweb::CacheInterface | |
enum | KeyState { kAvailable = 0, kNotFound = 1, kOverload = 2, kNetworkError = 3, kTimeout = 4 } |
typedef std::vector< KeyCallback > | MultiGetRequest |
Protected Member Functions inherited from net_instaweb::CacheInterface | |
void | ValidateAndReportResult (const GoogleString &key, KeyState state, Callback *callback) |
Invokes callback->ValidateCandidate() and callback->Done() as appropriate. | |
void | ReportMultiGetNotFound (MultiGetRequest *request) |
Interface to memcached via the apr_memcache2*, as documented in http://apr.apache.org/docs/apr-util/1.4/group___a_p_r___util___m_c.html.
While this class derives from CacheInterface, it is a blocking implementation, suitable for instantiating underneath an AsyncCache.
net_instaweb::AprMemCache::AprMemCache | ( | const ExternalClusterSpec & | cluster, |
int | thread_limit, | ||
Hasher * | hasher, | ||
Statistics * | statistics, | ||
Timer * | timer, | ||
MessageHandler * | handler | ||
) |
thread_limit is used to provide apr_memcache2_server_create with a hard maximum number of client connections to open.
bool net_instaweb::AprMemCache::Connect | ( | ) |
Connects to the server, returning whether the connection was successful or not.
bool net_instaweb::AprMemCache::GetStatus | ( | GoogleString * | status_string | ) |
Get detailed status in a string, returning false if the server failed to return status.
|
inlinevirtual |
Returns true if this cache is guaranteed to call its callbacks before returning from Get and MultiGet.
Implements net_instaweb::CacheInterface.
|
virtual |
Determines whether memcached is healthy enough to attempt another operation. Note that even though there may be multiple shards, some of which are healthy and some not, we don't currently track errors on a per-shard basis, so we effectively declare all the memcached instances unhealthy if any of them are.
Implements net_instaweb::CacheInterface.
|
virtual |
Gets multiple keys, calling multiple callbacks. Default implementation simply loops over all the keys and calls Get.
MultiGetRequest, declared above, is a vector of structs of keys and callbacks.
Ownership of the request is transferred to this function.
Reimplemented from net_instaweb::CacheInterface.
|
inlinevirtual |
To deal with underlying cache systems (e.g. memcached) that cannot tolerate arbitrary-sized keys, we use a hash of the key and put the key in the value, using the functions in key_value_codec.h.
To do this without pointlessly copying the value bytes, we use SharedString::Append(). However, that's not thread-safe. So when making a cache Asynchronous with AsyncCache, we must do the SharedString::Append call in the thread that initiates the Put, before queuing a threaded Put.
This method indicates whether a cache implementation requires encoding the keys in the value using key_value_codec.
Reimplemented from net_instaweb::CacheInterface.
|
inlinevirtual |
The name of this CacheInterface – used for logging and debugging.
It is strongly recommended that you provide a static GoogleString FormatName(...) method for use in formatting the Name() return, and in testing, e.g. in third_party/pagespeed/system/system_caches_test.cc.
Implements net_instaweb::CacheInterface.
|
virtual |
Puts a value into the cache. The value that is passed in is not modified, but the SharedString is passed by non-const pointer because its reference count is bumped.
Implements net_instaweb::CacheInterface.
|
virtual |
Performs a cache Put, but assumes the key has already been encoded into the value with key_value_codec. It is only valid to call this when MustEncodeKeyInValueOnPut() returns true.
Reimplemented from net_instaweb::CacheInterface.
void net_instaweb::AprMemCache::RecordError | ( | ) |
Records in statistics that a system error occurred, helping it detect when it's unhealthy if they are too frequent.
void net_instaweb::AprMemCache::set_timeout_us | ( | int | timeout_us | ) |
Sets the I/O timeout in microseconds. This should be called at setup time and not while there are operations in flight.
|
static |
Maximum number of errors tolerated within kHealthCheckpointIntervalMs, after which AprMemCache will declare itself unhealthy for kHealthCheckpointIntervalMs.
|
static |
Experimentally it seems large values larger than 1M bytes result in a failure, e.g. from load-tests: [Fri Jul 20 10:29:34 2012] [error] [mod_pagespeed 0.10.0.0-1699 @1522] AprMemCache::Put error: Internal error on key http://example.com/image.jpg, value-size 1393146 External to this class, we use a fallback cache (in Apache a FileCache) to handle too-large requests. This is managed by class FallbackCache in ../util.