Cache: Now also CacheRules is shared

Unnecessary methods were also removed from CachePT and CacheMT
as it does not make sense to create more than one single instance
of those per filter instance. Consequently there is no need for
them to be able to use an existing StorageFactory (and CacheRules).
This commit is contained in:
Johan Wikman
2016-11-30 09:58:01 +02:00
parent 93103fd64a
commit 9175295542
10 changed files with 19 additions and 103 deletions

View File

@ -36,9 +36,11 @@ Cache::~Cache()
//static
bool Cache::Create(const CACHE_CONFIG& config,
CacheRules** ppRules)
CacheRules** ppRules,
StorageFactory** ppFactory)
{
CacheRules* pRules = NULL;
StorageFactory* pFactory = NULL;
if (config.rules)
{
@ -50,26 +52,6 @@ bool Cache::Create(const CACHE_CONFIG& config,
}
if (pRules)
{
*ppRules = pRules;
}
else
{
MXS_ERROR("Could not create rules.");
}
return pRules != NULL;
}
//static
bool Cache::Create(const CACHE_CONFIG& config,
CacheRules** ppRules,
StorageFactory** ppFactory)
{
CacheRules* pRules = NULL;
StorageFactory* pFactory = NULL;
if (Create(config, &pRules))
{
pFactory = StorageFactory::Open(config.storage);
@ -84,6 +66,10 @@ bool Cache::Create(const CACHE_CONFIG& config,
delete pRules;
}
}
else
{
MXS_ERROR("Could not create rules.");
}
return pFactory != NULL;
}

View File

@ -84,9 +84,6 @@ protected:
SCacheRules sRules,
SStorageFactory sFactory);
static bool Create(const CACHE_CONFIG& config,
CacheRules** ppRules);
static bool Create(const CACHE_CONFIG& config,
CacheRules** ppRules,
StorageFactory** ppFactory);

View File

@ -54,26 +54,6 @@ CacheMT* CacheMT::Create(const std::string& name, const CACHE_CONFIG* pConfig)
return pCache;
}
// static
CacheMT* CacheMT::Create(const std::string& name, SStorageFactory sFactory, const CACHE_CONFIG* pConfig)
{
ss_dassert(pConfig);
ss_dassert(sFactory.get());
CacheMT* pCache = NULL;
CacheRules* pRules = NULL;
if (CacheSimple::Create(*pConfig, &pRules))
{
shared_ptr<CacheRules> sRules(pRules);
pCache = Create(name, pConfig, sRules, sFactory);
}
return pCache;
}
bool CacheMT::must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache)
{
LockGuard guard(&m_lockPending);

View File

@ -22,7 +22,6 @@ public:
~CacheMT();
static CacheMT* Create(const std::string& name, const CACHE_CONFIG* pConfig);
static CacheMT* Create(const std::string& name, SStorageFactory sFactory, const CACHE_CONFIG* pConfig);
bool must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache);

View File

@ -81,27 +81,6 @@ CachePT* CachePT::Create(const std::string& name, const CACHE_CONFIG* pConfig)
return pCache;
}
// static
CachePT* CachePT::Create(const std::string& name,
SStorageFactory sFactory,
const CACHE_CONFIG* pConfig)
{
ss_dassert(pConfig);
CachePT* pCache = NULL;
CacheRules* pRules = NULL;
if (Cache::Create(*pConfig, &pRules))
{
shared_ptr<CacheRules> sRules(pRules);
pCache = Create(name, pConfig, sRules, sFactory);
}
return pCache;
}
bool CachePT::must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache)
{
return thread_cache().must_refresh(key, pSessionCache);
@ -158,7 +137,7 @@ CachePT* CachePT::Create(const std::string& name,
CacheST* pCacheST = 0;
CPP_GUARD(pCacheST = CacheST::Create(namest, sFactory, pConfig));
CPP_GUARD(pCacheST = CacheST::Create(namest, sRules, sFactory, pConfig));
if (pCacheST)
{

View File

@ -23,7 +23,6 @@ public:
~CachePT();
static CachePT* Create(const std::string& name, const CACHE_CONFIG* pConfig);
static CachePT* Create(const std::string& name, SStorageFactory sFactory, const CACHE_CONFIG* pConfig);
bool must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache);

View File

@ -31,23 +31,6 @@ CacheSimple::~CacheSimple()
delete m_pStorage;
}
// static
bool CacheSimple::Create(const CACHE_CONFIG& config,
CacheRules** ppRules)
{
int rv = false;
CacheRules* pRules = NULL;
if (Cache::Create(config, &pRules))
{
*ppRules = pRules;
}
return pRules != NULL;;
}
// static
bool CacheSimple::Create(const CACHE_CONFIG& config,
CacheRules** ppRules,

View File

@ -39,9 +39,6 @@ protected:
SStorageFactory sFactory,
Storage* pStorage);
static bool Create(const CACHE_CONFIG& config,
CacheRules** ppRules);
static bool Create(const CACHE_CONFIG& config,
CacheRules** ppRules,
StorageFactory** ppFactory);

View File

@ -53,23 +53,16 @@ CacheST* CacheST::Create(const std::string& name, const CACHE_CONFIG* pConfig)
}
// static
CacheST* CacheST::Create(const std::string& name, SStorageFactory sFactory, const CACHE_CONFIG* pConfig)
CacheST* CacheST::Create(const std::string& name,
SCacheRules sRules,
SStorageFactory sFactory,
const CACHE_CONFIG* pConfig)
{
ss_dassert(pConfig);
ss_dassert(sRules.get());
ss_dassert(sFactory.get());
ss_dassert(pConfig);
CacheST* pCache = NULL;
CacheRules* pRules = NULL;
if (CacheSimple::Create(*pConfig, &pRules))
{
shared_ptr<CacheRules> sRules(pRules);
pCache = Create(name, pConfig, sRules, sFactory);
}
return pCache;
return Create(name, pConfig, sRules, sFactory);
}
bool CacheST::must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache)

View File

@ -21,7 +21,10 @@ public:
~CacheST();
static CacheST* Create(const std::string& name, const CACHE_CONFIG* pConfig);
static CacheST* Create(const std::string& name, SStorageFactory sFactory, const CACHE_CONFIG* pConfig);
static CacheST* Create(const std::string& name,
SCacheRules sRules,
SStorageFactory sFactory,
const CACHE_CONFIG* pConfig);
bool must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache);