Cache: Store name as string and not as char*

This commit is contained in:
Johan Wikman 2016-11-27 20:10:09 +02:00
parent 4f1f71a05a
commit 910a349f86
8 changed files with 36 additions and 35 deletions

View File

@ -19,11 +19,11 @@
#include "storagefactory.h"
#include "storage.h"
Cache::Cache(const char* zName,
Cache::Cache(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory)
: m_zName(zName)
: m_name(name)
, m_config(*pConfig)
, m_pRules(pRules)
, m_pFactory(pFactory)

View File

@ -13,6 +13,7 @@
*/
#include <maxscale/cdefs.h>
#include <string>
#include <maxscale/buffer.h>
#include <maxscale/session.h>
#include "cachefilter.h"
@ -73,10 +74,10 @@ public:
virtual cache_result_t delValue(const CACHE_KEY& key) = 0;
protected:
Cache(const char* zName,
Cache(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory);
CACHE_RULES* pRules,
StorageFactory* pFactory);
static bool Create(const CACHE_CONFIG& config,
CACHE_RULES** ppRules);
@ -90,7 +91,7 @@ private:
Cache& operator = (const Cache&);
protected:
const char* m_zName; // The name of the instance; the section name in the config.
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.
StorageFactory* m_pFactory; // The storage factory.

View File

@ -15,13 +15,13 @@
#include "storage.h"
#include "storagefactory.h"
CacheMT::CacheMT(const char* zName,
CacheMT::CacheMT(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory,
HASHTABLE* pPending,
Storage* pStorage)
: CacheSimple(zName, pConfig, pRules, pFactory, pPending, pStorage)
: CacheSimple(name, pConfig, pRules, pFactory, pPending, pStorage)
{
spinlock_init(&m_lockPending);
}
@ -30,7 +30,7 @@ CacheMT::~CacheMT()
{
}
CacheMT* CacheMT::Create(const char* zName, const CACHE_CONFIG* pConfig)
CacheMT* CacheMT::Create(const std::string& name, const CACHE_CONFIG* pConfig)
{
ss_dassert(pConfig);
@ -42,14 +42,14 @@ CacheMT* CacheMT::Create(const char* zName, const CACHE_CONFIG* pConfig)
if (CacheSimple::Create(*pConfig, &pRules, &pPending, &pFactory))
{
pCache = Create(zName, pConfig, pRules, pFactory, pPending);
pCache = Create(name, pConfig, pRules, pFactory, pPending);
}
return pCache;
}
// static
CacheMT* CacheMT::Create(const char* zName, StorageFactory* pFactory, const CACHE_CONFIG* pConfig)
CacheMT* CacheMT::Create(const std::string& name, StorageFactory* pFactory, const CACHE_CONFIG* pConfig)
{
ss_dassert(pConfig);
ss_dassert(pFactory);
@ -61,7 +61,7 @@ CacheMT* CacheMT::Create(const char* zName, StorageFactory* pFactory, const CACH
if (CacheSimple::Create(*pConfig, &pRules, &pPending))
{
pCache = Create(zName, pConfig, pRules, pFactory, pPending);
pCache = Create(name, pConfig, pRules, pFactory, pPending);
}
return pCache;
@ -88,7 +88,7 @@ void CacheMT::refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache
}
// static
CacheMT* CacheMT::Create(const char* zName,
CacheMT* CacheMT::Create(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory,
@ -100,11 +100,11 @@ CacheMT* CacheMT::Create(const char* zName,
int argc = pConfig->storage_argc;
char** argv = pConfig->storage_argv;
Storage* pStorage = pFactory->createStorage(CACHE_THREAD_MODEL_MT, zName, ttl, argc, argv);
Storage* pStorage = pFactory->createStorage(CACHE_THREAD_MODEL_MT, name.c_str(), ttl, argc, argv);
if (pStorage)
{
CPP_GUARD(pCache = new CacheMT(zName,
CPP_GUARD(pCache = new CacheMT(name,
pConfig,
pRules,
pFactory,

View File

@ -21,22 +21,22 @@ class CacheMT : public CacheSimple
public:
~CacheMT();
static CacheMT* Create(const char* zName, const CACHE_CONFIG* pConfig);
static CacheMT* Create(const char* zName, StorageFactory* pFactory, const CACHE_CONFIG* pConfig);
static CacheMT* Create(const std::string& name, const CACHE_CONFIG* pConfig);
static CacheMT* Create(const std::string& name, StorageFactory* pFactory, const CACHE_CONFIG* pConfig);
bool mustRefresh(const CACHE_KEY& key, const SessionCache* pSessionCache);
void refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache);
private:
CacheMT(const char* zName,
CacheMT(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory,
HASHTABLE* pPending,
Storage* pStorage);
static CacheMT* Create(const char* zName,
static CacheMT* Create(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory,

View File

@ -60,13 +60,13 @@ int hashcmp(const void* address1, const void* address2)
}
CacheSimple::CacheSimple(const char* zName,
CacheSimple::CacheSimple(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory,
HASHTABLE* pPending,
Storage* pStorage)
: Cache(zName, pConfig, pRules, pFactory)
: Cache(name, pConfig, pRules, pFactory)
, m_pPending(pPending)
, m_pStorage(pStorage)
{

View File

@ -32,7 +32,7 @@ public:
cache_result_t delValue(const CACHE_KEY& key);
protected:
CacheSimple(const char* zName,
CacheSimple(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory,

View File

@ -15,13 +15,13 @@
#include "storage.h"
#include "storagefactory.h"
CacheST::CacheST(const char* zName,
CacheST::CacheST(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory,
HASHTABLE* pPending,
Storage* pStorage)
: CacheSimple(zName, pConfig, pRules, pFactory, pPending, pStorage)
: CacheSimple(name, pConfig, pRules, pFactory, pPending, pStorage)
{
}
@ -29,7 +29,7 @@ CacheST::~CacheST()
{
}
CacheST* CacheST::Create(const char* zName, const CACHE_CONFIG* pConfig)
CacheST* CacheST::Create(const std::string& name, const CACHE_CONFIG* pConfig)
{
ss_dassert(pConfig);
@ -41,14 +41,14 @@ CacheST* CacheST::Create(const char* zName, const CACHE_CONFIG* pConfig)
if (CacheSimple::Create(*pConfig, &pRules, &pPending, &pFactory))
{
pCache = Create(zName, pConfig, pRules, pFactory, pPending);
pCache = Create(name, pConfig, pRules, pFactory, pPending);
}
return pCache;
}
// static
CacheST* CacheST::Create(const char* zName, StorageFactory* pFactory, const CACHE_CONFIG* pConfig)
CacheST* CacheST::Create(const std::string& name, StorageFactory* pFactory, const CACHE_CONFIG* pConfig)
{
ss_dassert(pConfig);
ss_dassert(pFactory);
@ -60,7 +60,7 @@ CacheST* CacheST::Create(const char* zName, StorageFactory* pFactory, const CACH
if (CacheSimple::Create(*pConfig, &pRules, &pPending))
{
pCache = Create(zName, pConfig, pRules, pFactory, pPending);
pCache = Create(name, pConfig, pRules, pFactory, pPending);
}
return pCache;
@ -81,7 +81,7 @@ void CacheST::refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache
}
// statis
CacheST* CacheST::Create(const char* zName,
CacheST* CacheST::Create(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory,
@ -93,11 +93,11 @@ CacheST* CacheST::Create(const char* zName,
int argc = pConfig->storage_argc;
char** argv = pConfig->storage_argv;
Storage* pStorage = pFactory->createStorage(CACHE_THREAD_MODEL_ST, zName, ttl, argc, argv);
Storage* pStorage = pFactory->createStorage(CACHE_THREAD_MODEL_ST, name.c_str(), ttl, argc, argv);
if (pStorage)
{
CPP_GUARD(pCache = new CacheST(zName,
CPP_GUARD(pCache = new CacheST(name,
pConfig,
pRules,
pFactory,

View File

@ -20,22 +20,22 @@ class CacheST : public CacheSimple
public:
~CacheST();
static CacheST* Create(const char* zName, const CACHE_CONFIG* pConfig);
static CacheST* Create(const char* zName, StorageFactory* pFactory, const CACHE_CONFIG* pConfig);
static CacheST* Create(const std::string& name, const CACHE_CONFIG* pConfig);
static CacheST* Create(const std::string& name, StorageFactory* pFactory, const CACHE_CONFIG* pConfig);
bool mustRefresh(const CACHE_KEY& key, const SessionCache* pSessionCache);
void refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache);
private:
CacheST(const char* zName,
CacheST(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory,
HASHTABLE* pPending,
Storage* pStorage);
static CacheST* Create(const char* zName,
static CacheST* Create(const std::string& name,
const CACHE_CONFIG* pConfig,
CACHE_RULES* pRules,
StorageFactory* pFactory,