proxygen
|
#include <FilePersistentCache.h>
Public Member Functions | |
FilePersistentCache (const std::string &file, std::size_t cacheCapacity, std::chrono::seconds syncInterval=std::chrono::duration_cast< std::chrono::seconds >(client::persistence::DEFAULT_CACHE_SYNC_INTERVAL), int nSyncRetries=client::persistence::DEFAULT_CACHE_SYNC_RETRIES) | |
FilePersistentCache (std::shared_ptr< folly::Executor > executor, const std::string &file, std::size_t cacheCapacity, std::chrono::seconds syncInterval, int nSyncRetries) | |
~FilePersistentCache () override | |
folly::Optional< V > | get (const K &key) override |
void | put (const K &key, const V &val) override |
bool | remove (const K &key) override |
void | clear (bool clearPersistence=false) override |
size_t | size () override |
void | setSyncOnDestroy (bool syncOnDestroy) |
Public Member Functions inherited from wangle::PersistentCache< K, V > | |
virtual | ~PersistentCache () |
Private Attributes | |
LRUPersistentCache< K, V, M >::Ptr | cache_ |
A PersistentCache implementation that used a regular file for storage. In memory structure fronts the file and the cache operations happen on it. Loading from and syncing to file are hidden from clients. Sync to file happens asynchronously on a separate thread at a configurable interval. Syncs to file on destruction as well.
NOTE NOTE NOTE: Although this class aims to be a cache for arbitrary, it relies heavily on folly::toJson, folly::dynamic and convertTo for serialization and deserialization. So It may not suit your need until true support arbitrary types is written.
Definition at line 40 of file FilePersistentCache.h.
wangle::FilePersistentCache< K, V, M >::FilePersistentCache | ( | const std::string & | file, |
std::size_t | cacheCapacity, | ||
std::chrono::seconds | syncInterval = std::chrono::duration_cast<std::chrono::seconds>( client::persistence::DEFAULT_CACHE_SYNC_INTERVAL) , |
||
int | nSyncRetries = client::persistence::DEFAULT_CACHE_SYNC_RETRIES |
||
) |
Definition at line 114 of file FilePersistentCache-inl.h.
wangle::FilePersistentCache< K, V, M >::FilePersistentCache | ( | std::shared_ptr< folly::Executor > | executor, |
const std::string & | file, | ||
std::size_t | cacheCapacity, | ||
std::chrono::seconds | syncInterval, | ||
int | nSyncRetries | ||
) |
Definition at line 126 of file FilePersistentCache-inl.h.
|
inlineoverride |
Definition at line 58 of file FilePersistentCache.h.
|
inlineoverridevirtual |
Empty the contents of the cache
Implements wangle::PersistentCache< K, V >.
Definition at line 75 of file FilePersistentCache.h.
References wangle::FilePersistentCache< K, V, M >::cache_, and wangle::LRUPersistentCache< K, V, MutexT >::clear().
|
inlineoverridevirtual |
PersistentCache operations
Implements wangle::PersistentCache< K, V >.
Definition at line 63 of file FilePersistentCache.h.
References wangle::FilePersistentCache< K, V, M >::cache_, and wangle::LRUPersistentCache< K, V, MutexT >::get().
Referenced by TYPED_TEST().
|
inlineoverridevirtual |
Set a value corresponding to a key
key | string, the key to set |
val | string, the value to set |
overwrites value if key has a value associated in the cache
Implements wangle::PersistentCache< K, V >.
Definition at line 67 of file FilePersistentCache.h.
References wangle::FilePersistentCache< K, V, M >::cache_, and wangle::LRUPersistentCache< K, V, MutexT >::put().
Referenced by TYPED_TEST().
|
inlineoverridevirtual |
Clear a cache entry associated with a key
key | string, the key to lookup and clear |
Implements wangle::PersistentCache< K, V >.
Definition at line 71 of file FilePersistentCache.h.
References wangle::FilePersistentCache< K, V, M >::cache_, and wangle::LRUPersistentCache< K, V, MutexT >::remove().
|
inline |
Definition at line 83 of file FilePersistentCache.h.
References wangle::FilePersistentCache< K, V, M >::cache_, and wangle::LRUPersistentCache< K, V, MutexT >::setSyncOnDestroy().
|
inlineoverridevirtual |
return the size of the cache
Implements wangle::PersistentCache< K, V >.
Definition at line 79 of file FilePersistentCache.h.
References wangle::FilePersistentCache< K, V, M >::cache_, and wangle::LRUPersistentCache< K, V, MutexT >::size().
Referenced by TYPED_TEST().
|
private |
Definition at line 88 of file FilePersistentCache.h.
Referenced by wangle::FilePersistentCache< K, V, M >::clear(), wangle::FilePersistentCache< K, V, M >::get(), wangle::FilePersistentCache< K, V, M >::put(), wangle::FilePersistentCache< K, V, M >::remove(), wangle::FilePersistentCache< K, V, M >::setSyncOnDestroy(), and wangle::FilePersistentCache< K, V, M >::size().