|
CppCommon 1.0.5.0
C++ Common Library
|
#include <filecache.h>
Public Types | |
| typedef std::function< bool(FileCache &cache, const std::string &key, const std::string &value, const Timespan &timeout)> | InsertHandler |
| File cache insert handler type. | |
Public Member Functions | |
| FileCache ()=default | |
| FileCache (const FileCache &)=delete | |
| FileCache (FileCache &&)=delete | |
| ~FileCache ()=default | |
| FileCache & | operator= (const FileCache &)=delete |
| FileCache & | operator= (FileCache &&)=delete |
| operator bool () const | |
| Check if the file cache is not empty. | |
| bool | empty () const |
| Is the file cache empty? | |
| size_t | size () const |
| Get the file cache size. | |
| bool | emplace (std::string &&key, std::string &&value, const Timespan &timeout=Timespan(0)) |
| Emplace a new cache value with the given timeout into the file cache. | |
| bool | insert (const std::string &key, const std::string &value, const Timespan &timeout=Timespan(0)) |
| Insert a new cache value with the given timeout into the file cache. | |
| std::pair< bool, std::string_view > | find (const std::string &key) |
| Try to find the cache value by the given key. | |
| std::pair< bool, std::string_view > | find (const std::string &key, Timestamp &timeout) |
| Try to find the cache value with timeout by the given key. | |
| bool | remove (const std::string &key) |
| Remove the cache value with the given key from the file cache. | |
| bool | insert_path (const CppCommon::Path &path, const std::string &prefix="/", const Timespan &timeout=Timespan(0), const InsertHandler &handler=[](FileCache &cache, const std::string &key, const std::string &value, const Timespan &timeout){ return cache.insert(key, value, timeout);}) |
| Insert a new cache path with the given timeout into the file cache. | |
| bool | find_path (const CppCommon::Path &path) |
| Try to find the cache path. | |
| bool | find_path (const CppCommon::Path &path, Timestamp &timeout) |
| Try to find the cache path with timeout. | |
| bool | remove_path (const CppCommon::Path &path) |
| Remove the cache path from the file cache. | |
| void | clear () |
| Clear the memory cache. | |
| void | watchdog (const UtcTimestamp &utc=UtcTimestamp()) |
| Watchdog the file cache. | |
| void | swap (FileCache &cache) noexcept |
| Swap two instances. | |
Friends | |
| void | swap (FileCache &cache1, FileCache &cache2) noexcept |
File cache.
File cache is used to cache files in memory with optional timeouts.
Thread-safe.
Definition at line 35 of file filecache.h.
| typedef std::function<bool (FileCache& cache, const std::string& key, const std::string& value, const Timespan& timeout)> CppCommon::FileCache::InsertHandler |
File cache insert handler type.
Definition at line 39 of file filecache.h.
|
default |
|
delete |
|
delete |
|
default |
| void CppCommon::FileCache::clear | ( | ) |
Clear the memory cache.
Definition at line 215 of file filecache.cpp.
| bool CppCommon::FileCache::emplace | ( | std::string && | key, |
| std::string && | value, | ||
| const Timespan & | timeout = Timespan(0) |
||
| ) |
Emplace a new cache value with the given timeout into the file cache.
| key | - Key to emplace |
| value | - Value to emplace |
| timeout | - Cache timeout (default is 0 - no timeout) |
Definition at line 13 of file filecache.cpp.
|
inline |
Is the file cache empty?
Definition at line 11 of file filecache.inl.
| std::pair< bool, std::string_view > CppCommon::FileCache::find | ( | const std::string & | key | ) |
Try to find the cache value by the given key.
| key | - Key to find |
Definition at line 55 of file filecache.cpp.
| std::pair< bool, std::string_view > CppCommon::FileCache::find | ( | const std::string & | key, |
| Timestamp & | timeout | ||
| ) |
Try to find the cache value with timeout by the given key.
| key | - Key to find |
| timeout | - Cache timeout value |
Definition at line 67 of file filecache.cpp.
| bool CppCommon::FileCache::find_path | ( | const CppCommon::Path & | path | ) |
Try to find the cache path.
| path | - Path to find |
Definition at line 166 of file filecache.cpp.
| bool CppCommon::FileCache::find_path | ( | const CppCommon::Path & | path, |
| Timestamp & | timeout | ||
| ) |
Try to find the cache path with timeout.
| path | - Path to find |
| timeout | - Cache timeout value |
Definition at line 178 of file filecache.cpp.
| bool CppCommon::FileCache::insert | ( | const std::string & | key, |
| const std::string & | value, | ||
| const Timespan & | timeout = Timespan(0) |
||
| ) |
Insert a new cache value with the given timeout into the file cache.
| key | - Key to insert |
| value | - Value to insert |
| timeout | - Cache timeout (default is 0 - no timeout) |
Definition at line 34 of file filecache.cpp.
| bool CppCommon::FileCache::insert_path | ( | const CppCommon::Path & | path, |
| const std::string & | prefix = "/", |
||
| const Timespan & | timeout = Timespan(0), |
||
| const InsertHandler & | handler = [](FileCache& cache, const std::string& key, const std::string& value, const Timespan& timeout){ return cache.insert(key, value, timeout); } |
||
| ) |
Insert a new cache path with the given timeout into the file cache.
| path | - Path to insert |
| prefix | - Cache prefix (default is "/") |
| timeout | - Cache timeout (default is 0 - no timeout) |
| handler | - Cache insert handler (default is 'return cache.insert(key, value, timeout)') |
Definition at line 104 of file filecache.cpp.
|
inlineexplicit |
Check if the file cache is not empty.
Definition at line 50 of file filecache.h.
| bool CppCommon::FileCache::remove | ( | const std::string & | key | ) |
Remove the cache value with the given key from the file cache.
| key | - Key to remove |
Definition at line 80 of file filecache.cpp.
| bool CppCommon::FileCache::remove_path | ( | const CppCommon::Path & | path | ) |
Remove the cache path from the file cache.
| path | - Path to remove |
Definition at line 191 of file filecache.cpp.
|
inline |
Get the file cache size.
Definition at line 17 of file filecache.inl.
|
noexcept |
Swap two instances.
Definition at line 273 of file filecache.cpp.
| void CppCommon::FileCache::watchdog | ( | const UtcTimestamp & | utc = UtcTimestamp() | ) |
Definition at line 23 of file filecache.inl.