This class provides a Least Recently Used (LRU) cache implementation.
The cache stores cache items in two ways: the first is through a map for quick look-up times for clients and the other as a set of pointers whose items are sorted in ascending order according to last access time (recent to least recent).
Items should be removed directly if expired or no longer needed.
#include <cache/YiLRUCache.h>
Public Member Functions | |
| CYILRUCache () | |
| ~CYILRUCache () | |
| void | Add (const CYIUrl &url, std::unique_ptr< const CYILRUData > pData, uint32_t uMaxAgeInSeconds=0) |
| bool | Contains (const CYIUrl &url) const |
| int32_t | GetSize () const |
| std::vector< CYIUrl > | GetUrls () const |
| const CYILRUData * | GetData (const CYIUrl &url) const |
| bool | HasExpired (const CYIUrl &url) const |
| CYIDateTime | GetExpiryDate (const CYIUrl &url) const |
| void | Remove (const CYIUrl &url) |
| const CYILRUData * | Peek (const CYIUrl &url) const |
| const CYILRUData * | Peek (int32_t nIndex) const |
| void | SetExpireTime (uint32_t uMaxAgeInSeconds, const CYIUrl &url) |
| void | LogCacheItems () const |
| CYILRUCache::CYILRUCache | ( | ) |
| CYILRUCache::~CYILRUCache | ( | ) |
| void CYILRUCache::Add | ( | const CYIUrl & | url, |
| std::unique_ptr< const CYILRUData > | pData, | ||
| uint32_t | uMaxAgeInSeconds = 0 |
||
| ) |
Adds an item to the cache. The parameter nMaxAgeInSeconds is optional, but will cause the HasExpired call to always return false.
| bool CYILRUCache::Contains | ( | const CYIUrl & | url | ) | const |
Returns true if the cache contains the specified url.
| const CYILRUData* CYILRUCache::GetData | ( | const CYIUrl & | url | ) | const |
Returns the LRU data object associated with the url. This will adjust the access time to the current time, thus moving it to the back of the cache.
| CYIDateTime CYILRUCache::GetExpiryDate | ( | const CYIUrl & | url | ) | const |
Returns the expiry date for the item associated with url. If url was not found in the cache, an invalid time is returned.
| int32_t CYILRUCache::GetSize | ( | ) | const |
Returns the number of items in the cache.
| std::vector<CYIUrl> CYILRUCache::GetUrls | ( | ) | const |
Returns a list of managed URLs.
| bool CYILRUCache::HasExpired | ( | const CYIUrl & | url | ) | const |
Returns true if the item at the associated url has expired.
| void CYILRUCache::LogCacheItems | ( | ) | const |
Logs the URLs and expiration dates of all cached items.
| const CYILRUData* CYILRUCache::Peek | ( | const CYIUrl & | url | ) | const |
Returns the cached item data with the matching url, but do not adjust the access time, thus preserving its position in the cache.
| const CYILRUData* CYILRUCache::Peek | ( | int32_t | nIndex | ) | const |
Returns the cached item at specified nIndex.
| void CYILRUCache::Remove | ( | const CYIUrl & | url | ) |
Remove the LRU item using the associated url.
| void CYILRUCache::SetExpireTime | ( | uint32_t | uMaxAgeInSeconds, |
| const CYIUrl & | url | ||
| ) |
Sets the time-to-expire interval for the cached item associate with the url.