Cache: Now use CacheRules instead of CACHE_RULES

This commit is contained in:
Johan Wikman 2016-11-30 09:27:30 +02:00
parent 2e4ac55aa4
commit d52145054f
12 changed files with 56 additions and 54 deletions

View File

@ -19,10 +19,10 @@
#include "storagefactory.h"
#include "storage.h"
Cache::Cache(const std::string& name,
Cache::Cache(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory)
CacheRules* pRules,
StorageFactory* pFactory)
: m_name(name)
, m_config(*pConfig)
, m_pRules(pRules)
@ -32,23 +32,23 @@ Cache::Cache(const std::string& name,
Cache::~Cache()
{
cache_rules_free(m_pRules);
delete m_pRules;
delete m_pFactory;
}
//static
bool Cache::Create(const CACHE_CONFIG& config,
CACHE_RULES** ppRules)
CacheRules** ppRules)
{
CACHE_RULES* pRules = NULL;
CacheRules* pRules = NULL;
if (config.rules)
{
pRules = cache_rules_load(config.rules, config.debug);
pRules = CacheRules::load(config.rules, config.debug);
}
else
{
pRules = cache_rules_create(config.debug);
pRules = CacheRules::create(config.debug);
}
if (pRules)
@ -65,10 +65,10 @@ bool Cache::Create(const CACHE_CONFIG& config,
//static
bool Cache::Create(const CACHE_CONFIG& config,
CACHE_RULES** ppRules,
CacheRules** ppRules,
StorageFactory** ppFactory)
{
CACHE_RULES* pRules = NULL;
CacheRules* pRules = NULL;
StorageFactory* pFactory = NULL;
if (Create(config, &pRules))
@ -83,7 +83,7 @@ bool Cache::Create(const CACHE_CONFIG& config,
else
{
MXS_ERROR("Could not open storage factory '%s'.", config.storage);
cache_rules_free(pRules);
delete pRules;
}
}
@ -92,10 +92,10 @@ bool Cache::Create(const CACHE_CONFIG& config,
bool Cache::should_store(const char* zDefaultDb, const GWBUF* pQuery)
{
return cache_rules_should_store(m_pRules, zDefaultDb, pQuery);
return m_pRules->should_store(zDefaultDb, pQuery);
}
bool Cache::should_use(const SESSION* pSession)
{
return cache_rules_should_use(m_pRules, pSession);
return m_pRules->should_use(pSession);
}

View File

@ -77,14 +77,14 @@ public:
protected:
Cache(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory);
static bool Create(const CACHE_CONFIG& config,
CACHE_RULES** ppRules);
CacheRules** ppRules);
static bool Create(const CACHE_CONFIG& config,
CACHE_RULES** ppRules,
CacheRules** ppRules,
StorageFactory** ppFactory);
private:
@ -94,6 +94,6 @@ private:
protected:
const std::string m_name; // The name of the instance; the section name in the config.
const CACHE_CONFIG& m_config; // The configuration of the cache instance.
CACHE_RULES* m_pRules; // The rules of the cache instance.
CacheRules* m_pRules; // The rules of the cache instance.
StorageFactory* m_pFactory; // The storage factory.
};

View File

@ -16,11 +16,11 @@
#include "storage.h"
#include "storagefactory.h"
CacheMT::CacheMT(const std::string& name,
CacheMT::CacheMT(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory,
Storage* pStorage)
CacheRules* pRules,
StorageFactory* pFactory,
Storage* pStorage)
: CacheSimple(name, pConfig, pRules, pFactory, pStorage)
{
spinlock_init(&m_lockPending);
@ -38,7 +38,7 @@ CacheMT* CacheMT::Create(const std::string& name, const CACHE_CONFIG* pConfig)
CacheMT* pCache = NULL;
CACHE_RULES* pRules = NULL;
CacheRules* pRules = NULL;
StorageFactory* pFactory = NULL;
if (CacheSimple::Create(*pConfig, &pRules, &pFactory))
@ -57,7 +57,7 @@ CacheMT* CacheMT::Create(const std::string& name, StorageFactory* pFactory, cons
CacheMT* pCache = NULL;
CACHE_RULES* pRules = NULL;
CacheRules* pRules = NULL;
if (CacheSimple::Create(*pConfig, &pRules))
{
@ -84,7 +84,7 @@ void CacheMT::refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache
// static
CacheMT* CacheMT::Create(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory)
{
CacheMT* pCache = NULL;
@ -111,7 +111,7 @@ CacheMT* CacheMT::Create(const std::string& name,
if (!pCache)
{
delete pStorage;
cache_rules_free(pRules);
delete pRules;
delete pFactory;
}
}

View File

@ -31,13 +31,13 @@ public:
private:
CacheMT(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory,
Storage* pStorage);
static CacheMT* Create(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory);
private:

View File

@ -47,7 +47,7 @@ inline int thread_index()
CachePT::CachePT(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory,
const Caches& caches)
: Cache(name, pConfig, pRules, pFactory)
@ -67,7 +67,7 @@ CachePT* CachePT::Create(const std::string& name, const CACHE_CONFIG* pConfig)
CachePT* pCache = NULL;
CACHE_RULES* pRules = NULL;
CacheRules* pRules = NULL;
StorageFactory* pFactory = NULL;
if (Cache::Create(*pConfig, &pRules, &pFactory))
@ -87,7 +87,7 @@ CachePT* CachePT::Create(const std::string& name,
CachePT* pCache = NULL;
CACHE_RULES* pRules = NULL;
CacheRules* pRules = NULL;
if (Cache::Create(*pConfig, &pRules))
{
@ -130,7 +130,7 @@ cache_result_t CachePT::del_value(const CACHE_KEY& key)
// static
CachePT* CachePT::Create(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory)
{
CachePT* pCache = NULL;
@ -176,7 +176,7 @@ CachePT* CachePT::Create(const std::string& name,
}
catch (const std::exception&)
{
cache_rules_free(pRules);
delete pRules;
delete pFactory;
}

View File

@ -43,13 +43,13 @@ private:
CachePT(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory,
const Caches& caches);
static CachePT* Create(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory);
Cache& thread_cache();

View File

@ -18,7 +18,7 @@
CacheSimple::CacheSimple(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory,
Storage* pStorage)
: Cache(name, pConfig, pRules, pFactory)
@ -34,11 +34,11 @@ CacheSimple::~CacheSimple()
// static
bool CacheSimple::Create(const CACHE_CONFIG& config,
CACHE_RULES** ppRules)
CacheRules** ppRules)
{
int rv = false;
CACHE_RULES* pRules = NULL;
CacheRules* pRules = NULL;
if (Cache::Create(config, &pRules))
{
@ -50,12 +50,12 @@ bool CacheSimple::Create(const CACHE_CONFIG& config,
// static
bool CacheSimple::Create(const CACHE_CONFIG& config,
CACHE_RULES** ppRules,
CacheRules** ppRules,
StorageFactory** ppFactory)
{
int rv = false;
CACHE_RULES* pRules = NULL;
CacheRules* pRules = NULL;
StorageFactory* pFactory = NULL;
if (Cache::Create(config, &pRules, &pFactory))

View File

@ -35,15 +35,15 @@ public:
protected:
CacheSimple(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory,
Storage* pStorage);
static bool Create(const CACHE_CONFIG& config,
CACHE_RULES** ppRules);
CacheRules** ppRules);
static bool Create(const CACHE_CONFIG& config,
CACHE_RULES** ppRules,
CacheRules** ppRules,
StorageFactory** ppFactory);

View File

@ -16,11 +16,11 @@
#include "storage.h"
#include "storagefactory.h"
CacheST::CacheST(const std::string& name,
CacheST::CacheST(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory,
Storage* pStorage)
CacheRules* pRules,
StorageFactory* pFactory,
Storage* pStorage)
: CacheSimple(name, pConfig, pRules, pFactory, pStorage)
{
MXS_NOTICE("Created single threaded cache.");
@ -36,7 +36,7 @@ CacheST* CacheST::Create(const std::string& name, const CACHE_CONFIG* pConfig)
CacheST* pCache = NULL;
CACHE_RULES* pRules = NULL;
CacheRules* pRules = NULL;
StorageFactory* pFactory = NULL;
if (CacheSimple::Create(*pConfig, &pRules, &pFactory))
@ -55,7 +55,7 @@ CacheST* CacheST::Create(const std::string& name, StorageFactory* pFactory, cons
CacheST* pCache = NULL;
CACHE_RULES* pRules = NULL;
CacheRules* pRules = NULL;
if (CacheSimple::Create(*pConfig, &pRules))
{
@ -78,7 +78,7 @@ void CacheST::refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache
// static
CacheST* CacheST::Create(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory)
{
CacheST* pCache = NULL;
@ -105,7 +105,7 @@ CacheST* CacheST::Create(const std::string& name,
if (!pCache)
{
delete pStorage;
cache_rules_free(pRules);
delete pRules;
delete pFactory;
}
}

View File

@ -30,13 +30,13 @@ public:
private:
CacheST(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory,
Storage* pStorage);
static CacheST* Create(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
CacheRules* pRules,
StorageFactory* pFactory);
private:
CacheST(const CacheST&);

View File

@ -351,6 +351,7 @@ CacheRules::~CacheRules()
cache_rules_free(prules_);
}
// static
CacheRules* CacheRules::create(uint32_t debug)
{
CacheRules* pthis = NULL;
@ -365,6 +366,7 @@ CacheRules* CacheRules::create(uint32_t debug)
return pthis;
}
// static
CacheRules* CacheRules::load(const char *zpath, uint32_t debug)
{
CacheRules* pthis = NULL;

View File

@ -161,7 +161,7 @@ public:
*
* @return An empty rules object, or NULL in case of error.
*/
CacheRules* create(uint32_t debug);
static CacheRules* create(uint32_t debug);
/**
* Loads the caching rules from a file and returns corresponding object.
@ -171,7 +171,7 @@ public:
*
* @return The corresponding rules object, or NULL in case of error.
*/
CacheRules* load(const char *zpath, uint32_t debug);
static CacheRules* load(const char *zpath, uint32_t debug);
/**
* Returns boolean indicating whether the result of the query should be stored.