Cache: Make Cache abstract

The methods that need to be different depending on the thread model
are now pure virtual.
This commit is contained in:
Johan Wikman
2016-11-25 14:25:35 +02:00
parent 3ba8525063
commit 7a0d6307fe
3 changed files with 3 additions and 33 deletions

View File

@ -143,36 +143,6 @@ bool Cache::shouldUse(const SESSION* pSession)
return cache_rules_should_use(m_pRules, pSession);
}
bool Cache::mustRefresh(const char* pKey, const SessionCache* pSessionCache)
{
long key = hash_of_key(pKey);
spinlock_acquire(&m_lockPending);
// TODO: Remove the internal locking of hashtable. The internal
// TODO: locking is no good if you need transactional behaviour.
// TODO: Now we lock twice.
void *pValue = hashtable_fetch(m_pPending, (void*)pKey);
if (!pValue)
{
// It's not being fetched, so we make a note that we are.
hashtable_add(m_pPending, (void*)pKey, (void*)pSessionCache);
}
spinlock_release(&m_lockPending);
return pValue == NULL;
}
void Cache::refreshed(const char* pKey, const SessionCache* pSessionCache)
{
long key = hash_of_key(pKey);
spinlock_acquire(&m_lockPending);
ss_dassert(hashtable_fetch(m_pPending, (void*)pKey) == pSessionCache);
ss_debug(int n =) hashtable_delete(m_pPending, (void*)pKey);
ss_dassert(n == 1);
spinlock_release(&m_lockPending);
}
cache_result_t Cache::getKey(const char* zDefaultDb,
const GWBUF* pQuery,
char* pKey)

View File

@ -53,7 +53,7 @@ public:
*
* @return True, if the session cache should refresh the data.
*/
virtual bool mustRefresh(const char* pKey, const SessionCache* pSessionCache);
virtual bool mustRefresh(const char* pKey, const SessionCache* pSessionCache) = 0;
/**
* To inform the cache that a particular item has been updated upon request.
@ -61,7 +61,7 @@ public:
* @param pKey The hashed key for a query.
* @param pSessionCache The session cache informing.
*/
virtual void refreshed(const char* pKey, const SessionCache* pSessionCache);
virtual void refreshed(const char* pKey, const SessionCache* pSessionCache) = 0;
const CACHE_CONFIG& config() const { return m_config; }
@ -103,5 +103,4 @@ protected:
StorageFactory* m_pFactory; // The storage factory.
Storage* m_pStorage; // The storage instance to use.
HASHTABLE* m_pPending; // Pending items; being fetched from the backend.
SPINLOCK m_lockPending; // Lock used for protecting 'pending'.
};

View File

@ -13,6 +13,7 @@
*/
#include <maxscale/cdefs.h>
#include <maxscale/spinlock.h>
#include "cache.h"
class CacheMT : public Cache