Tkrzw
|
Double-layered LRU cache. More...
#include <tkrzw_containers.h>
Classes | |
class | Iterator |
Iterator to access each record. More... | |
Public Member Functions | |
DoubleLRUCache (size_t hot_capacity, size_t warm_capacity) | |
Constructor. More... | |
std::shared_ptr< VALUETYPE > | Add (int64_t id, VALUETYPE *value) |
Adds a record. More... | |
void | GiveBack (int64_t id, std::shared_ptr< VALUETYPE > &&value) |
Gives back a record which has been removed. More... | |
std::shared_ptr< VALUETYPE > | Get (int64_t id, bool promotion) |
Gets the value of a record. More... | |
void | Remove (int64_t id) |
Removes a record. More... | |
std::shared_ptr< VALUETYPE > | RemoveLRU (int64_t *id=nullptr) |
Removes the least recent used record. More... | |
size_t | Size () const |
Gets the number of records. More... | |
bool | IsEmpty () const |
Checks whether no records exist. More... | |
bool | IsSaturated () const |
Checks whether stored records exceeds the capacity. More... | |
void | Clear () |
Removes all records. More... | |
Iterator | MakeIterator () |
Makes an iterator for each record. More... | |
Double-layered LRU cache.
VALUETYPE | the value type. |
tkrzw::DoubleLRUCache< VALUETYPE >::DoubleLRUCache | ( | size_t | hot_capacity, |
size_t | warm_capacity | ||
) |
Constructor.
hot_capacity | The maximum number of records in the hot cache. |
warm_capacity | The maximum number of records in the worm cache. |
std::shared_ptr< VALUETYPE > tkrzw::DoubleLRUCache< VALUETYPE >::Add | ( | int64_t | id, |
VALUETYPE * | value | ||
) |
Adds a record.
id | The ID of the record. |
value | The pointer to the value object. Ownership is taken. |
If there is an existing record of the same ID, the new value object is just deleted and the return value refers to the existing record.
void tkrzw::DoubleLRUCache< VALUETYPE >::GiveBack | ( | int64_t | id, |
std::shared_ptr< VALUETYPE > && | value | ||
) |
Gives back a record which has been removed.
id | The ID of the record. |
value | The moved pointer to the value object. Ownership is taken. |
std::shared_ptr< VALUETYPE > tkrzw::DoubleLRUCache< VALUETYPE >::Get | ( | int64_t | id, |
bool | promotion | ||
) |
Gets the value of a record.
id | The ID of the record. |
promotion | True if the record can be promoted to the hot list. |
void tkrzw::DoubleLRUCache< VALUETYPE >::Remove | ( | int64_t | id | ) |
Removes a record.
id | The ID of the record. |
std::shared_ptr< VALUETYPE > tkrzw::DoubleLRUCache< VALUETYPE >::RemoveLRU | ( | int64_t * | id = nullptr | ) |
Removes the least recent used record.
id | The pointer to store the ID of the record. If it is nullptr, it is ignored. |
size_t tkrzw::DoubleLRUCache< VALUETYPE >::Size |
Gets the number of records.
bool tkrzw::DoubleLRUCache< VALUETYPE >::IsEmpty |
Checks whether no records exist.
bool tkrzw::DoubleLRUCache< VALUETYPE >::IsSaturated |
Checks whether stored records exceeds the capacity.
void tkrzw::DoubleLRUCache< VALUETYPE >::Clear |
Removes all records.
DoubleLRUCache< VALUETYPE >::Iterator tkrzw::DoubleLRUCache< VALUETYPE >::MakeIterator |
Makes an iterator for each record.