Page Speed Optimization Libraries
1.13.35.1
|
#include "purge_context.h"
Public Types | |
typedef Callback2< bool, StringPiece > | PurgeCallback |
typedef Callback1< const CopyOnWrite< PurgeSet > & > | PurgeSetCallback |
Public Member Functions | |
PurgeContext (StringPiece filename, FileSystem *file_system, Timer *timer, int max_bytes_in_cache, ThreadSystem *thread_system, NamedLockManager *lock_manager, Scheduler *scheduler, Statistics *statistics, MessageHandler *handler) | |
void | set_request_batching_delay_ms (int64 delay_ms) |
void | AddPurgeUrl (StringPiece url, int64 timestamp_ms, PurgeCallback *callback) |
void | SetCachePurgeGlobalTimestampMs (int64 timestamp_ms, PurgeCallback *callback) |
void | PollFileSystem () |
void | SetUpdateCallback (PurgeSetCallback *cb) |
void | set_enable_purge (bool x) |
Static Public Member Functions | |
static void | InitStats (Statistics *statistics) |
Static Public Attributes | |
static const int | kCheckCacheIntervalMs = 5 * Timer::kSecondMs |
static const char | kCancellations [] |
Variable names. | |
static const char | kContentions [] |
static const char | kFileParseFailures [] |
static const char | kFileStats [] |
static const char | kFileWriteFailures [] |
static const char | kFileWrites [] |
static const char | kPurgeIndex [] |
static const char | kPurgePollTimestampMs [] |
static const char | kStatCalls [] |
Friends | |
class | PurgeContextTest |
Handles purging of URLs, atomically persisting them to disk, allowing multiple concurrent threads/processes to handle purge requests and propagate them to the other processes.
All public methods in this class are thread-safe.
This class depends on Statistics being functional. If statistics are off, then cache purging may be slower, but it will still work.
void net_instaweb::PurgeContext::AddPurgeUrl | ( | StringPiece | url, |
int64 | timestamp_ms, | ||
PurgeCallback * | callback | ||
) |
Adds a URL to the purge-set, atomically updating the purge file, and transmitting the results to the system, attempting to do so within a bounded amount of time.
Calls callback(true, "") if the invalidation succeeded (was able to grab the global lock in a finite amount of time), and callback(false, "reason") if it failed. If we fail to take the lock then the invalidation is dropped on the floor, and statistics "purge_cancellations" is bumped.
void net_instaweb::PurgeContext::PollFileSystem | ( | ) |
Periodically updates the purge-set from disk if enough time has expired. This can be called on every request.
|
inline |
Indicates whether individual URL purging is supported. If false, then we only take the cache.flush file timestamp to do full cache flushes. If true, then we read and parse the contents of the file to find the global invalidation time and cache-flush times for the individual entries.
|
inline |
By default, PurgeContext will try to acquire the lock and write the cache.purge file as soon as it is called. This may present a significant load to the file system, causing delays.
In a multi-threaded or asynchronous environment (e.g. any environment other than Apache HTTPD pre-fork MPM), it is desirable to batch up requests for a time (e.g. 1 second) before writing the updated cache file.
void net_instaweb::PurgeContext::SetCachePurgeGlobalTimestampMs | ( | int64 | timestamp_ms, |
PurgeCallback * | callback | ||
) |
Sets the global invalidation timestamp.
Calls callback(true, "") if the invalidation succeeded (was able to grab the global lock in a finite amount of time), and callback(false, "reason") if it failed. If we fail to take the lock then the invalidation is dropped on the floor, and statistics "purge_cancellations" is bumped.
void net_instaweb::PurgeContext::SetUpdateCallback | ( | PurgeSetCallback * | cb | ) |
To test whether URLs are purged, you must capture a PurgeSet by registering a callback. The PurgeSet is passed to the callback using a CopyOnWrite wrapper so that the callback can efficiently share the storage.
IsValid calls can then be made using the PurgeSet captured by the callback.
|
static |
The source-of-truth of the purge data is kept in files. These files are checked for changes via stat every 5 seconds.