Make Cache/Storage const correct
- From the outside, all actions getting data from the cache/storage are const. - Update documentation.
This commit is contained in:
20
server/modules/filter/cache/cache.hh
vendored
20
server/modules/filter/cache/cache.hh
vendored
@ -83,12 +83,28 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession) = 0;
|
virtual void refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession) = 0;
|
||||||
|
|
||||||
virtual cache_result_t get_key(const char* zDefaultDb, const GWBUF* pQuery, CACHE_KEY* pKey) = 0;
|
/**
|
||||||
|
* See @Storage::get_key
|
||||||
|
*/
|
||||||
|
virtual cache_result_t get_key(const char* zDefaultDb,
|
||||||
|
const GWBUF* pQuery,
|
||||||
|
CACHE_KEY* pKey) const = 0;
|
||||||
|
|
||||||
virtual cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppValue) = 0;
|
/**
|
||||||
|
* See @Storage::get_value
|
||||||
|
*/
|
||||||
|
virtual cache_result_t get_value(const CACHE_KEY& key,
|
||||||
|
uint32_t flags,
|
||||||
|
GWBUF** ppValue) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See @Storage::put_value
|
||||||
|
*/
|
||||||
virtual cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue) = 0;
|
virtual cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See @Storage::del_value
|
||||||
|
*/
|
||||||
virtual cache_result_t del_value(const CACHE_KEY& key) = 0;
|
virtual cache_result_t del_value(const CACHE_KEY& key) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -102,6 +102,7 @@ typedef struct cache_storage_api
|
|||||||
*
|
*
|
||||||
* @param capabilities On successful return, contains a bitmask of
|
* @param capabilities On successful return, contains a bitmask of
|
||||||
* cache_storage_capabilities_t values.
|
* cache_storage_capabilities_t values.
|
||||||
|
*
|
||||||
* @return True if the initialization succeeded, false otherwise.
|
* @return True if the initialization succeeded, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool (*initialize)(uint32_t* capabilities);
|
bool (*initialize)(uint32_t* capabilities);
|
||||||
@ -185,6 +186,7 @@ typedef struct cache_storage_api
|
|||||||
* @param flags Mask of cache_flags_t values.
|
* @param flags Mask of cache_flags_t values.
|
||||||
* @param result Pointer to variable that after a successful return will
|
* @param result Pointer to variable that after a successful return will
|
||||||
* point to a GWBUF.
|
* point to a GWBUF.
|
||||||
|
*
|
||||||
* @return CACHE_RESULT_OK if item was found,
|
* @return CACHE_RESULT_OK if item was found,
|
||||||
* CACHE_RESULT_STALE if CACHE_FLAGS_INCLUDE_STALE was specified in
|
* CACHE_RESULT_STALE if CACHE_FLAGS_INCLUDE_STALE was specified in
|
||||||
* flags and the item was found but stale,
|
* flags and the item was found but stale,
|
||||||
@ -203,6 +205,7 @@ typedef struct cache_storage_api
|
|||||||
* @param key A key generated with get_key.
|
* @param key A key generated with get_key.
|
||||||
* @param value Pointer to GWBUF containing the value to be stored.
|
* @param value Pointer to GWBUF containing the value to be stored.
|
||||||
* Must be one contiguous buffer.
|
* Must be one contiguous buffer.
|
||||||
|
*
|
||||||
* @return CACHE_RESULT_OK if item was successfully put,
|
* @return CACHE_RESULT_OK if item was successfully put,
|
||||||
* CACHE_RESULT_OUT_OF_RESOURCES if item could not be put, due to
|
* CACHE_RESULT_OUT_OF_RESOURCES if item could not be put, due to
|
||||||
* some resource having become exhausted, or some other error code.
|
* some resource having become exhausted, or some other error code.
|
||||||
@ -216,6 +219,7 @@ typedef struct cache_storage_api
|
|||||||
*
|
*
|
||||||
* @param storage Pointer to a CACHE_STORAGE.
|
* @param storage Pointer to a CACHE_STORAGE.
|
||||||
* @param key A key generated with get_key.
|
* @param key A key generated with get_key.
|
||||||
|
*
|
||||||
* @return CACHE_RESULT_OK if item was successfully deleted. Note that
|
* @return CACHE_RESULT_OK if item was successfully deleted. Note that
|
||||||
* CACHE_RESULT_OK may be returned also if the entry was not present.
|
* CACHE_RESULT_OK may be returned also if the entry was not present.
|
||||||
*/
|
*/
|
||||||
|
4
server/modules/filter/cache/cachept.cc
vendored
4
server/modules/filter/cache/cachept.cc
vendored
@ -122,12 +122,12 @@ json_t* CachePT::get_info(uint32_t what) const
|
|||||||
return pInfo;
|
return pInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t CachePT::get_key(const char* zDefaultDb, const GWBUF* pQuery, CACHE_KEY* pKey)
|
cache_result_t CachePT::get_key(const char* zDefaultDb, const GWBUF* pQuery, CACHE_KEY* pKey) const
|
||||||
{
|
{
|
||||||
return thread_cache().get_key(zDefaultDb, pQuery, pKey);
|
return thread_cache().get_key(zDefaultDb, pQuery, pKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t CachePT::get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppValue)
|
cache_result_t CachePT::get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppValue) const
|
||||||
{
|
{
|
||||||
return thread_cache().get_value(key, flags, ppValue);
|
return thread_cache().get_value(key, flags, ppValue);
|
||||||
}
|
}
|
||||||
|
9
server/modules/filter/cache/cachept.hh
vendored
9
server/modules/filter/cache/cachept.hh
vendored
@ -30,9 +30,9 @@ public:
|
|||||||
|
|
||||||
json_t* get_info(uint32_t what) const;
|
json_t* get_info(uint32_t what) const;
|
||||||
|
|
||||||
cache_result_t get_key(const char* zDefaultDb, const GWBUF* pQuery, CACHE_KEY* pKey);
|
cache_result_t get_key(const char* zDefaultDb, const GWBUF* pQuery, CACHE_KEY* pKey) const;
|
||||||
|
|
||||||
cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppValue);
|
cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppValue) const;
|
||||||
|
|
||||||
cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue);
|
cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue);
|
||||||
|
|
||||||
@ -55,6 +55,11 @@ private:
|
|||||||
|
|
||||||
Cache& thread_cache();
|
Cache& thread_cache();
|
||||||
|
|
||||||
|
const Cache& thread_cache() const
|
||||||
|
{
|
||||||
|
return const_cast<CachePT*>(this)->thread_cache();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CachePT(const Cache&);
|
CachePT(const Cache&);
|
||||||
CachePT& operator = (const CachePT&);
|
CachePT& operator = (const CachePT&);
|
||||||
|
4
server/modules/filter/cache/cachesimple.cc
vendored
4
server/modules/filter/cache/cachesimple.cc
vendored
@ -52,14 +52,14 @@ bool CacheSimple::Create(const CACHE_CONFIG& config,
|
|||||||
|
|
||||||
cache_result_t CacheSimple::get_key(const char* zDefaultDb,
|
cache_result_t CacheSimple::get_key(const char* zDefaultDb,
|
||||||
const GWBUF* pQuery,
|
const GWBUF* pQuery,
|
||||||
CACHE_KEY* pKey)
|
CACHE_KEY* pKey) const
|
||||||
{
|
{
|
||||||
return m_pStorage->get_key(zDefaultDb, pQuery, pKey);
|
return m_pStorage->get_key(zDefaultDb, pQuery, pKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t CacheSimple::get_value(const CACHE_KEY& key,
|
cache_result_t CacheSimple::get_value(const CACHE_KEY& key,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
GWBUF** ppValue)
|
GWBUF** ppValue) const
|
||||||
{
|
{
|
||||||
return m_pStorage->get_value(key, flags, ppValue);
|
return m_pStorage->get_value(key, flags, ppValue);
|
||||||
}
|
}
|
||||||
|
4
server/modules/filter/cache/cachesimple.hh
vendored
4
server/modules/filter/cache/cachesimple.hh
vendored
@ -25,9 +25,9 @@ class CacheSimple : public Cache
|
|||||||
public:
|
public:
|
||||||
~CacheSimple();
|
~CacheSimple();
|
||||||
|
|
||||||
cache_result_t get_key(const char* zDefaultDb, const GWBUF* pQuery, CACHE_KEY* pKey);
|
cache_result_t get_key(const char* zDefaultDb, const GWBUF* pQuery, CACHE_KEY* pKey) const;
|
||||||
|
|
||||||
cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppValue);
|
cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppValue) const;
|
||||||
|
|
||||||
cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue);
|
cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue);
|
||||||
|
|
||||||
|
13
server/modules/filter/cache/lrustorage.cc
vendored
13
server/modules/filter/cache/lrustorage.cc
vendored
@ -29,7 +29,7 @@ LRUStorage::~LRUStorage()
|
|||||||
|
|
||||||
cache_result_t LRUStorage::get_key(const char* zdefault_db,
|
cache_result_t LRUStorage::get_key(const char* zdefault_db,
|
||||||
const GWBUF* pquery,
|
const GWBUF* pquery,
|
||||||
CACHE_KEY* pkey)
|
CACHE_KEY* pkey) const
|
||||||
{
|
{
|
||||||
return pstorage_->get_key(zdefault_db, pquery, pkey);
|
return pstorage_->get_key(zdefault_db, pquery, pkey);
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ cache_result_t LRUStorage::do_get_info(uint32_t what,
|
|||||||
|
|
||||||
cache_result_t LRUStorage::do_get_value(const CACHE_KEY& key,
|
cache_result_t LRUStorage::do_get_value(const CACHE_KEY& key,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
GWBUF** ppvalue)
|
GWBUF** ppvalue) const
|
||||||
{
|
{
|
||||||
NodesPerKey::iterator i = nodes_per_key_.find(key);
|
NodesPerKey::iterator i = nodes_per_key_.find(key);
|
||||||
bool existed = (i != nodes_per_key_.end());
|
bool existed = (i != nodes_per_key_.end());
|
||||||
@ -121,8 +121,7 @@ cache_result_t LRUStorage::do_get_value(const CACHE_KEY& key,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorage::do_put_value(const CACHE_KEY& key,
|
cache_result_t LRUStorage::do_put_value(const CACHE_KEY& key, const GWBUF* pvalue)
|
||||||
const GWBUF* pvalue)
|
|
||||||
{
|
{
|
||||||
cache_result_t result = CACHE_RESULT_ERROR;
|
cache_result_t result = CACHE_RESULT_ERROR;
|
||||||
|
|
||||||
@ -264,8 +263,7 @@ cache_result_t LRUStorage::do_del_value(const CACHE_KEY& key)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorage::do_get_head(CACHE_KEY* pKey,
|
cache_result_t LRUStorage::do_get_head(CACHE_KEY* pKey, GWBUF** ppValue) const
|
||||||
GWBUF** ppValue)
|
|
||||||
{
|
{
|
||||||
cache_result_t result = CACHE_RESULT_NOT_FOUND;
|
cache_result_t result = CACHE_RESULT_NOT_FOUND;
|
||||||
|
|
||||||
@ -285,8 +283,7 @@ cache_result_t LRUStorage::do_get_head(CACHE_KEY* pKey,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorage::do_get_tail(CACHE_KEY* pKey,
|
cache_result_t LRUStorage::do_get_tail(CACHE_KEY* pKey, GWBUF** ppValue) const
|
||||||
GWBUF** ppValue)
|
|
||||||
{
|
{
|
||||||
cache_result_t result = CACHE_RESULT_NOT_FOUND;
|
cache_result_t result = CACHE_RESULT_NOT_FOUND;
|
||||||
|
|
||||||
|
43
server/modules/filter/cache/lrustorage.hh
vendored
43
server/modules/filter/cache/lrustorage.hh
vendored
@ -28,73 +28,52 @@ public:
|
|||||||
*/
|
*/
|
||||||
cache_result_t get_key(const char* zDefaultDb,
|
cache_result_t get_key(const char* zDefaultDb,
|
||||||
const GWBUF* pQuery,
|
const GWBUF* pQuery,
|
||||||
CACHE_KEY* pKey);
|
CACHE_KEY* pKey) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LRUStorage(Storage* pstorage, uint64_t max_count, uint64_t max_size);
|
LRUStorage(Storage* pstorage, uint64_t max_count, uint64_t max_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about the LRU storage and the underlying real
|
|
||||||
* storage.
|
|
||||||
*
|
|
||||||
* @see Storage::get_info
|
* @see Storage::get_info
|
||||||
*/
|
*/
|
||||||
cache_result_t do_get_info(uint32_t what, json_t** ppInfo) const;
|
cache_result_t do_get_info(uint32_t what, json_t** ppInfo) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the value from the underlying storage and, if found, moves the
|
|
||||||
* entry to the top of the LRU list.
|
|
||||||
*
|
|
||||||
* @see Storage::get_value
|
* @see Storage::get_value
|
||||||
*/
|
*/
|
||||||
cache_result_t do_get_value(const CACHE_KEY& key,
|
cache_result_t do_get_value(const CACHE_KEY& key,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
GWBUF** ppValue);
|
GWBUF** ppValue) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the value to the underlying storage and, if successful, either
|
|
||||||
* places the entry at or moves the existing entry to the top of the LRU
|
|
||||||
* list.
|
|
||||||
*
|
|
||||||
* @see Storage::put_value
|
* @see Storage::put_value
|
||||||
*/
|
*/
|
||||||
cache_result_t do_put_value(const CACHE_KEY& key,
|
cache_result_t do_put_value(const CACHE_KEY& key,
|
||||||
const GWBUF* pValue);
|
const GWBUF* pValue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the value from the underlying storage and, if successful, removes
|
|
||||||
* the entry from the LRU list.
|
|
||||||
*
|
|
||||||
* @see Storage::del_value
|
* @see Storage::del_value
|
||||||
*/
|
*/
|
||||||
cache_result_t do_del_value(const CACHE_KEY& key);
|
cache_result_t do_del_value(const CACHE_KEY& key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the head item.
|
|
||||||
*
|
|
||||||
* @see Storage::get_head
|
* @see Storage::get_head
|
||||||
*/
|
*/
|
||||||
cache_result_t do_get_head(CACHE_KEY* pKey,
|
cache_result_t do_get_head(CACHE_KEY* pKey,
|
||||||
GWBUF** ppValue);
|
GWBUF** ppValue) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the tail item.
|
|
||||||
*
|
|
||||||
* @see Storage::get_tail
|
* @see Storage::get_tail
|
||||||
*/
|
*/
|
||||||
cache_result_t do_get_tail(CACHE_KEY* pKey,
|
cache_result_t do_get_tail(CACHE_KEY* pKey,
|
||||||
GWBUF** ppValue);
|
GWBUF** ppValue) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the size of the storage.
|
|
||||||
*
|
|
||||||
* @see Storage::getSize
|
* @see Storage::getSize
|
||||||
*/
|
*/
|
||||||
cache_result_t do_get_size(uint64_t* pSize) const;
|
cache_result_t do_get_size(uint64_t* pSize) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of items in the storage.
|
|
||||||
*
|
|
||||||
* @see Storage::getItems
|
* @see Storage::getItems
|
||||||
*/
|
*/
|
||||||
cache_result_t do_get_items(uint64_t* pItems) const;
|
cache_result_t do_get_items(uint64_t* pItems) const;
|
||||||
@ -222,11 +201,11 @@ private:
|
|||||||
uint64_t evictions; /*< How many times an item has been evicted from the cache. */
|
uint64_t evictions; /*< How many times an item has been evicted from the cache. */
|
||||||
};
|
};
|
||||||
|
|
||||||
Storage* pstorage_; /*< The actual storage. */
|
Storage* pstorage_; /*< The actual storage. */
|
||||||
uint64_t max_count_; /*< The maximum number of items in the LRU list, */
|
uint64_t max_count_; /*< The maximum number of items in the LRU list, */
|
||||||
uint64_t max_size_; /*< The maximum size of all cached items. */
|
uint64_t max_size_; /*< The maximum size of all cached items. */
|
||||||
Stats stats_; /*< Cache statistics. */
|
mutable Stats stats_; /*< Cache statistics. */
|
||||||
NodesPerKey nodes_per_key_; /*< Mapping from cache keys to corresponding Node. */
|
mutable NodesPerKey nodes_per_key_; /*< Mapping from cache keys to corresponding Node. */
|
||||||
Node* phead_; /*< The node at the LRU list. */
|
mutable Node* phead_; /*< The node at the LRU list. */
|
||||||
Node* ptail_; /*< The node at bottom of the LRU list.*/
|
mutable Node* ptail_; /*< The node at bottom of the LRU list.*/
|
||||||
};
|
};
|
||||||
|
15
server/modules/filter/cache/lrustoragemt.cc
vendored
15
server/modules/filter/cache/lrustoragemt.cc
vendored
@ -47,15 +47,14 @@ cache_result_t LRUStorageMT::get_info(uint32_t what,
|
|||||||
|
|
||||||
cache_result_t LRUStorageMT::get_value(const CACHE_KEY& key,
|
cache_result_t LRUStorageMT::get_value(const CACHE_KEY& key,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
GWBUF** ppvalue)
|
GWBUF** ppvalue) const
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(lock_);
|
SpinLockGuard guard(lock_);
|
||||||
|
|
||||||
return do_get_value(key, flags, ppvalue);
|
return do_get_value(key, flags, ppvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageMT::put_value(const CACHE_KEY& key,
|
cache_result_t LRUStorageMT::put_value(const CACHE_KEY& key, const GWBUF* pvalue)
|
||||||
const GWBUF* pvalue)
|
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(lock_);
|
SpinLockGuard guard(lock_);
|
||||||
|
|
||||||
@ -69,20 +68,18 @@ cache_result_t LRUStorageMT::del_value(const CACHE_KEY& key)
|
|||||||
return do_del_value(key);
|
return do_del_value(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageMT::get_head(CACHE_KEY* pKey,
|
cache_result_t LRUStorageMT::get_head(CACHE_KEY* pKey, GWBUF** ppHead) const
|
||||||
GWBUF** ppValue)
|
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(lock_);
|
SpinLockGuard guard(lock_);
|
||||||
|
|
||||||
return LRUStorage::do_get_head(pKey, ppValue);
|
return LRUStorage::do_get_head(pKey, ppHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageMT::get_tail(CACHE_KEY* pKey,
|
cache_result_t LRUStorageMT::get_tail(CACHE_KEY* pKey, GWBUF** ppTail) const
|
||||||
GWBUF** ppValue)
|
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(lock_);
|
SpinLockGuard guard(lock_);
|
||||||
|
|
||||||
return LRUStorage::do_get_tail(pKey, ppValue);
|
return LRUStorage::do_get_tail(pKey, ppTail);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageMT::get_size(uint64_t* pSize) const
|
cache_result_t LRUStorageMT::get_size(uint64_t* pSize) const
|
||||||
|
6
server/modules/filter/cache/lrustoragemt.hh
vendored
6
server/modules/filter/cache/lrustoragemt.hh
vendored
@ -28,7 +28,7 @@ public:
|
|||||||
|
|
||||||
cache_result_t get_value(const CACHE_KEY& key,
|
cache_result_t get_value(const CACHE_KEY& key,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
GWBUF** ppvalue);
|
GWBUF** ppvalue) const;
|
||||||
|
|
||||||
cache_result_t put_value(const CACHE_KEY& key,
|
cache_result_t put_value(const CACHE_KEY& key,
|
||||||
const GWBUF* pvalue);
|
const GWBUF* pvalue);
|
||||||
@ -36,10 +36,10 @@ public:
|
|||||||
cache_result_t del_value(const CACHE_KEY& key);
|
cache_result_t del_value(const CACHE_KEY& key);
|
||||||
|
|
||||||
cache_result_t get_head(CACHE_KEY* pKey,
|
cache_result_t get_head(CACHE_KEY* pKey,
|
||||||
GWBUF** ppValue);
|
GWBUF** ppValue) const;
|
||||||
|
|
||||||
cache_result_t get_tail(CACHE_KEY* pKey,
|
cache_result_t get_tail(CACHE_KEY* pKey,
|
||||||
GWBUF** ppValue);
|
GWBUF** ppValue) const;
|
||||||
|
|
||||||
cache_result_t get_size(uint64_t* pSize) const;
|
cache_result_t get_size(uint64_t* pSize) const;
|
||||||
|
|
||||||
|
11
server/modules/filter/cache/lrustoragest.cc
vendored
11
server/modules/filter/cache/lrustoragest.cc
vendored
@ -41,13 +41,12 @@ cache_result_t LRUStorageST::get_info(uint32_t what,
|
|||||||
|
|
||||||
cache_result_t LRUStorageST::get_value(const CACHE_KEY& key,
|
cache_result_t LRUStorageST::get_value(const CACHE_KEY& key,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
GWBUF** ppvalue)
|
GWBUF** ppvalue) const
|
||||||
{
|
{
|
||||||
return LRUStorage::do_get_value(key, flags, ppvalue);
|
return LRUStorage::do_get_value(key, flags, ppvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageST::put_value(const CACHE_KEY& key,
|
cache_result_t LRUStorageST::put_value(const CACHE_KEY& key, const GWBUF* pvalue)
|
||||||
const GWBUF* pvalue)
|
|
||||||
{
|
{
|
||||||
return LRUStorage::do_put_value(key, pvalue);
|
return LRUStorage::do_put_value(key, pvalue);
|
||||||
}
|
}
|
||||||
@ -57,14 +56,12 @@ cache_result_t LRUStorageST::del_value(const CACHE_KEY& key)
|
|||||||
return LRUStorage::do_del_value(key);
|
return LRUStorage::do_del_value(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageST::get_head(CACHE_KEY* pKey,
|
cache_result_t LRUStorageST::get_head(CACHE_KEY* pKey, GWBUF** ppValue) const
|
||||||
GWBUF** ppValue)
|
|
||||||
{
|
{
|
||||||
return LRUStorage::do_get_head(pKey, ppValue);
|
return LRUStorage::do_get_head(pKey, ppValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageST::get_tail(CACHE_KEY* pKey,
|
cache_result_t LRUStorageST::get_tail(CACHE_KEY* pKey, GWBUF** ppValue) const
|
||||||
GWBUF** ppValue)
|
|
||||||
{
|
{
|
||||||
return LRUStorage::do_get_tail(pKey, ppValue);
|
return LRUStorage::do_get_tail(pKey, ppValue);
|
||||||
}
|
}
|
||||||
|
6
server/modules/filter/cache/lrustoragest.hh
vendored
6
server/modules/filter/cache/lrustoragest.hh
vendored
@ -27,7 +27,7 @@ public:
|
|||||||
|
|
||||||
cache_result_t get_value(const CACHE_KEY& key,
|
cache_result_t get_value(const CACHE_KEY& key,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
GWBUF** ppValue);
|
GWBUF** ppValue) const;
|
||||||
|
|
||||||
cache_result_t put_value(const CACHE_KEY& key,
|
cache_result_t put_value(const CACHE_KEY& key,
|
||||||
const GWBUF* pValue);
|
const GWBUF* pValue);
|
||||||
@ -35,10 +35,10 @@ public:
|
|||||||
cache_result_t del_value(const CACHE_KEY& key);
|
cache_result_t del_value(const CACHE_KEY& key);
|
||||||
|
|
||||||
cache_result_t get_head(CACHE_KEY* pKey,
|
cache_result_t get_head(CACHE_KEY* pKey,
|
||||||
GWBUF** ppValue);
|
GWBUF** ppValue) const;
|
||||||
|
|
||||||
cache_result_t get_tail(CACHE_KEY* pKey,
|
cache_result_t get_tail(CACHE_KEY* pKey,
|
||||||
GWBUF** ppValue);
|
GWBUF** ppValue) const;
|
||||||
|
|
||||||
cache_result_t get_size(uint64_t* pSize) const;
|
cache_result_t get_size(uint64_t* pSize) const;
|
||||||
|
|
||||||
|
130
server/modules/filter/cache/storage.hh
vendored
130
server/modules/filter/cache/storage.hh
vendored
@ -25,30 +25,140 @@ public:
|
|||||||
|
|
||||||
virtual ~Storage();
|
virtual ~Storage();
|
||||||
|
|
||||||
virtual cache_result_t get_info(uint32_t what,
|
/**
|
||||||
json_t** ppInfo) const = 0;
|
* Returns information about the storage.
|
||||||
|
*
|
||||||
|
* @param what Bitmask of cache_storage_info_t values.
|
||||||
|
* @param info Upon successful return points to json_t object containing
|
||||||
|
* information. The caller should call @c json_decref on the
|
||||||
|
* object when it is no longer needed.
|
||||||
|
*
|
||||||
|
* @return CACHE_RESULT_OK if a json object could be created.
|
||||||
|
*/
|
||||||
|
virtual cache_result_t get_info(uint32_t what, json_t** ppInfo) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a key for a GWBUF.
|
||||||
|
*
|
||||||
|
* @param zDefaultDb The default DB or NULL.
|
||||||
|
* @param query An SQL query. Must be one contiguous buffer.
|
||||||
|
* @param pKey Pointer to object where key will be stored.
|
||||||
|
*
|
||||||
|
* @return CACHE_RESULT_OK if a key was created, otherwise some error code.
|
||||||
|
*/
|
||||||
virtual cache_result_t get_key(const char* zDefaultDb,
|
virtual cache_result_t get_key(const char* zDefaultDb,
|
||||||
const GWBUF* pQuery,
|
const GWBUF* pQuery,
|
||||||
CACHE_KEY* pKey) = 0;
|
CACHE_KEY* pKey) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a value from the cache.
|
||||||
|
*
|
||||||
|
* @param key A key generated with get_key.
|
||||||
|
* @param flags Mask of cache_flags_t values.
|
||||||
|
* @param ppValue Pointer to variable that after a successful return will
|
||||||
|
* point to a GWBUF.
|
||||||
|
*
|
||||||
|
* @return CACHE_RESULT_OK if item was found,
|
||||||
|
* CACHE_RESULT_STALE if CACHE_FLAGS_INCLUDE_STALE was specified in
|
||||||
|
* flags and the item was found but stale,
|
||||||
|
* CACHE_RESULT_NOT_FOUND if item was not found (which may be because
|
||||||
|
* the ttl was reached), or some other error code.
|
||||||
|
*/
|
||||||
virtual cache_result_t get_value(const CACHE_KEY& key,
|
virtual cache_result_t get_value(const CACHE_KEY& key,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
GWBUF** ppValue) = 0;
|
GWBUF** ppValue) const = 0;
|
||||||
|
|
||||||
virtual cache_result_t put_value(const CACHE_KEY& key,
|
/**
|
||||||
const GWBUF* pValue) = 0;
|
* Put a value to the cache.
|
||||||
|
*
|
||||||
|
* @param key A key generated with get_key.
|
||||||
|
* @param pValue Pointer to GWBUF containing the value to be stored.
|
||||||
|
* Must be one contiguous buffer.
|
||||||
|
* @return CACHE_RESULT_OK if item was successfully put,
|
||||||
|
* CACHE_RESULT_OUT_OF_RESOURCES if item could not be put, due to
|
||||||
|
* some resource having become exhausted, or some other error code.
|
||||||
|
*/
|
||||||
|
virtual cache_result_t put_value(const CACHE_KEY& key, const GWBUF* pValue) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a value from the cache.
|
||||||
|
*
|
||||||
|
* @param storage Pointer to a CACHE_STORAGE.
|
||||||
|
* @param key A key generated with get_key.
|
||||||
|
*
|
||||||
|
* @return CACHE_RESULT_OK if item was successfully deleted. Note that
|
||||||
|
* CACHE_RESULT_OK may be returned also if the entry was not present.
|
||||||
|
*/
|
||||||
virtual cache_result_t del_value(const CACHE_KEY& key) = 0;
|
virtual cache_result_t del_value(const CACHE_KEY& key) = 0;
|
||||||
|
|
||||||
virtual cache_result_t get_head(CACHE_KEY* pKey,
|
/**
|
||||||
GWBUF** ppValue) = 0;
|
* Get the head item from the storage. This is only intended for testing and
|
||||||
|
* debugging purposes and if the storage is being used by different threads
|
||||||
|
* at the same time, the returned result may be incorrect the moment it has
|
||||||
|
* been returned.
|
||||||
|
*
|
||||||
|
* @param key Pointer to variable that after a successful return will
|
||||||
|
* contain the key.
|
||||||
|
* @param ppHead Pointer to variable that after a successful return will
|
||||||
|
* point to a GWBUF.
|
||||||
|
*
|
||||||
|
* @return CACHE_RESULT_OK if the head item was returned,
|
||||||
|
* CACHE_RESULT_NOT_FOUND if the cache is empty,
|
||||||
|
* CACHE_RESULT_OUT_OF_RESOURCES if the storage is incapable of
|
||||||
|
* returning the head, and
|
||||||
|
* CACHE_RESULT_ERROR otherwise.
|
||||||
|
*/
|
||||||
|
virtual cache_result_t get_head(CACHE_KEY* pKey, GWBUF** ppHead) const = 0;
|
||||||
|
|
||||||
virtual cache_result_t get_tail(CACHE_KEY* pKey,
|
/**
|
||||||
GWBUF** ppValue) = 0;
|
* Get the tail item from the cache. This is only intended for testing and
|
||||||
|
* debugging purposes and if the storage is being used by different threads
|
||||||
|
* at the same time, the returned result may become incorrect the moment it
|
||||||
|
* has been returned.
|
||||||
|
*
|
||||||
|
* @param key Pointer to variable that after a successful return will
|
||||||
|
* contain the key.
|
||||||
|
* @param ppTail Pointer to variable that after a successful return will
|
||||||
|
* point to a GWBUF.
|
||||||
|
*
|
||||||
|
* @return CACHE_RESULT_OK if the head item was returned,
|
||||||
|
* CACHE_RESULT_NOT_FOUND if the cache is empty,
|
||||||
|
* CACHE_RESULT_OUT_OF_RESOURCES if the storage is incapable of
|
||||||
|
* returning the tail, and
|
||||||
|
* CACHE_RESULT_ERROR otherwise.
|
||||||
|
*/
|
||||||
|
virtual cache_result_t get_tail(CACHE_KEY* pKey, GWBUF** ppTail) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current size of the storage. This is only intended for testing and
|
||||||
|
* debugging purposes and if the storage is being used by different threads
|
||||||
|
* at the same time, the returned result may become incorrect the moment it
|
||||||
|
* has been returned.
|
||||||
|
*
|
||||||
|
* @param pSize Pointer to variable that after a successful return will
|
||||||
|
* contain the current size of the storage.
|
||||||
|
*
|
||||||
|
* @return CACHE_RESULT_OK if the size was returned,
|
||||||
|
* CACHE_RESULT_OUT_OF_RESOURCES if the storage
|
||||||
|
* is incapable of returning the size, and
|
||||||
|
* CACHE_RESULT_ERROR otherwise.
|
||||||
|
*/
|
||||||
virtual cache_result_t get_size(uint64_t* pSize) const = 0;
|
virtual cache_result_t get_size(uint64_t* pSize) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current number of items in the storage. This is only intended for
|
||||||
|
* testing and debugging purposes and if the storage is being used by different
|
||||||
|
* threads at the same time, the returned result may become incorrect the moment
|
||||||
|
* it has been returned.
|
||||||
|
*
|
||||||
|
* @param pItems Pointer to variable that after a successful return will
|
||||||
|
* contain the current number of items in the storage.
|
||||||
|
*
|
||||||
|
* @return CACHE_RESULT_OK if the size was returned,
|
||||||
|
* CACHE_RESULT_OUT_OF_RESOURCES if the storage
|
||||||
|
* is incapable of returning the size, and
|
||||||
|
* CACHE_RESULT_ERROR otherwise.
|
||||||
|
*/
|
||||||
virtual cache_result_t get_items(uint64_t* pItems) const = 0;
|
virtual cache_result_t get_items(uint64_t* pItems) const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
20
server/modules/filter/cache/storagereal.cc
vendored
20
server/modules/filter/cache/storagereal.cc
vendored
@ -27,28 +27,26 @@ StorageReal::~StorageReal()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t StorageReal::get_info(uint32_t flags,
|
cache_result_t StorageReal::get_info(uint32_t flags, json_t** ppInfo) const
|
||||||
json_t** ppInfo) const
|
|
||||||
{
|
{
|
||||||
return m_pApi->getInfo(m_pStorage, flags, ppInfo);
|
return m_pApi->getInfo(m_pStorage, flags, ppInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t StorageReal::get_key(const char* zDefaultDb,
|
cache_result_t StorageReal::get_key(const char* zDefaultDb,
|
||||||
const GWBUF* pQuery,
|
const GWBUF* pQuery,
|
||||||
CACHE_KEY* pKey)
|
CACHE_KEY* pKey) const
|
||||||
{
|
{
|
||||||
return m_pApi->getKey(m_pStorage, zDefaultDb, pQuery, pKey);
|
return m_pApi->getKey(m_pStorage, zDefaultDb, pQuery, pKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t StorageReal::get_value(const CACHE_KEY& key,
|
cache_result_t StorageReal::get_value(const CACHE_KEY& key,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
GWBUF** ppValue)
|
GWBUF** ppValue) const
|
||||||
{
|
{
|
||||||
return m_pApi->getValue(m_pStorage, &key, flags, ppValue);
|
return m_pApi->getValue(m_pStorage, &key, flags, ppValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t StorageReal::put_value(const CACHE_KEY& key,
|
cache_result_t StorageReal::put_value(const CACHE_KEY& key, const GWBUF* pValue)
|
||||||
const GWBUF* pValue)
|
|
||||||
{
|
{
|
||||||
return m_pApi->putValue(m_pStorage, &key, pValue);
|
return m_pApi->putValue(m_pStorage, &key, pValue);
|
||||||
}
|
}
|
||||||
@ -58,16 +56,14 @@ cache_result_t StorageReal::del_value(const CACHE_KEY& key)
|
|||||||
return m_pApi->delValue(m_pStorage, &key);
|
return m_pApi->delValue(m_pStorage, &key);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t StorageReal::get_head(CACHE_KEY* pKey,
|
cache_result_t StorageReal::get_head(CACHE_KEY* pKey, GWBUF** ppHead) const
|
||||||
GWBUF** ppValue)
|
|
||||||
{
|
{
|
||||||
return m_pApi->getHead(m_pStorage, pKey, ppValue);
|
return m_pApi->getHead(m_pStorage, pKey, ppHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t StorageReal::get_tail(CACHE_KEY* pKey,
|
cache_result_t StorageReal::get_tail(CACHE_KEY* pKey, GWBUF** ppTail) const
|
||||||
GWBUF** ppValue)
|
|
||||||
{
|
{
|
||||||
return m_pApi->getTail(m_pStorage, pKey, ppValue);
|
return m_pApi->getTail(m_pStorage, pKey, ppTail);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t StorageReal::get_size(uint64_t* pSize) const
|
cache_result_t StorageReal::get_size(uint64_t* pSize) const
|
||||||
|
10
server/modules/filter/cache/storagereal.hh
vendored
10
server/modules/filter/cache/storagereal.hh
vendored
@ -21,15 +21,15 @@ public:
|
|||||||
~StorageReal();
|
~StorageReal();
|
||||||
|
|
||||||
cache_result_t get_info(uint32_t flags,
|
cache_result_t get_info(uint32_t flags,
|
||||||
json_t** ppInfo) const;
|
json_t** ppInfo) const;
|
||||||
|
|
||||||
cache_result_t get_key(const char* zDefaultDb,
|
cache_result_t get_key(const char* zDefaultDb,
|
||||||
const GWBUF* pQuery,
|
const GWBUF* pQuery,
|
||||||
CACHE_KEY* pKey);
|
CACHE_KEY* pKey) const;
|
||||||
|
|
||||||
cache_result_t get_value(const CACHE_KEY& key,
|
cache_result_t get_value(const CACHE_KEY& key,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
GWBUF** ppValue);
|
GWBUF** ppValue) const;
|
||||||
|
|
||||||
cache_result_t put_value(const CACHE_KEY& key,
|
cache_result_t put_value(const CACHE_KEY& key,
|
||||||
const GWBUF* pValue);
|
const GWBUF* pValue);
|
||||||
@ -37,10 +37,10 @@ public:
|
|||||||
cache_result_t del_value(const CACHE_KEY& key);
|
cache_result_t del_value(const CACHE_KEY& key);
|
||||||
|
|
||||||
cache_result_t get_head(CACHE_KEY* pKey,
|
cache_result_t get_head(CACHE_KEY* pKey,
|
||||||
GWBUF** ppValue);
|
GWBUF** ppValue) const;
|
||||||
|
|
||||||
cache_result_t get_tail(CACHE_KEY* pKey,
|
cache_result_t get_tail(CACHE_KEY* pKey,
|
||||||
GWBUF** ppValue);
|
GWBUF** ppValue) const;
|
||||||
|
|
||||||
cache_result_t get_size(uint64_t* pSize) const;
|
cache_result_t get_size(uint64_t* pSize) const;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user