Cache: Add cache for single thread

This commit is contained in:
Johan Wikman
2016-11-25 15:46:19 +02:00
parent 279bf7e2fa
commit 5bae5b8b8d
3 changed files with 123 additions and 1 deletions

View File

@ -1,5 +1,5 @@
if (JANSSON_FOUND) if (JANSSON_FOUND)
add_library(cache SHARED cache.cc cachefilter.cc cachemt.cc rules.cc sessioncache.cc storage.cc storagefactory.cc) add_library(cache SHARED cache.cc cachefilter.cc cachemt.cc cachest.cc rules.cc sessioncache.cc storage.cc storagefactory.cc)
target_link_libraries(cache maxscale-common jansson) target_link_libraries(cache maxscale-common jansson)
set_target_properties(cache PROPERTIES VERSION "1.0.0") set_target_properties(cache PROPERTIES VERSION "1.0.0")
set_target_properties(cache PROPERTIES LINK_FLAGS -Wl,-z,defs) set_target_properties(cache PROPERTIES LINK_FLAGS -Wl,-z,defs)

82
server/modules/filter/cache/cachest.cc vendored Normal file
View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 2016 MariaDB Corporation Ab
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
*
* Change Date: 2019-07-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#include "cachest.h"
#include "storage.h"
#include "storagefactory.h"
CacheST::CacheST(const char* zName,
CACHE_CONFIG& config,
CACHE_RULES* pRules,
StorageFactory* pFactory,
Storage* pStorage,
HASHTABLE* pPending)
: Cache(zName, config, pRules, pFactory, pStorage, pPending)
{
}
CacheST::~CacheST()
{
}
CacheST* CacheST::Create(const char* zName, CACHE_CONFIG& config)
{
CacheST* pCache = NULL;
CACHE_RULES* pRules = NULL;
HASHTABLE* pPending = NULL;
StorageFactory* pFactory = NULL;
if (Cache::Create(config, &pRules, &pFactory, &pPending))
{
uint32_t ttl = config.ttl;
int argc = config.storage_argc;
char** argv = config.storage_argv;
Storage* pStorage = pFactory->createStorage(CACHE_THREAD_MODEL_ST, zName, ttl, argc, argv);
if (pStorage)
{
CPP_GUARD(pCache = new CacheST(zName,
config,
pRules,
pFactory,
pStorage,
pPending));
if (!pCache)
{
cache_rules_free(pRules);
hashtable_free(pPending);
delete pStorage;
delete pFactory;
}
}
}
return pCache;
}
bool CacheST::mustRefresh(const CACHE_KEY& key, const SessionCache* pSessionCache)
{
long k = hashOfKey(key);
return Cache::mustRefresh(k, pSessionCache);
}
void CacheST::refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache)
{
long k = hashOfKey(key);
Cache::refreshed(k, pSessionCache);
}

40
server/modules/filter/cache/cachest.h vendored Normal file
View File

@ -0,0 +1,40 @@
#pragma once
/*
* Copyright (c) 2016 MariaDB Corporation Ab
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
*
* Change Date: 2019-07-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#include <maxscale/cdefs.h>
#include "cache.h"
class CacheST : public Cache
{
public:
~CacheST();
static CacheST* Create(const char* zName, CACHE_CONFIG& config);
bool mustRefresh(const CACHE_KEY& key, const SessionCache* pSessionCache);
void refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache);
private:
CacheST(const char* zName,
CACHE_CONFIG& config,
CACHE_RULES* pRules,
StorageFactory* pFactory,
Storage* pStorage,
HASHTABLE* pPending);
private:
CacheST(const CacheST&);
CacheST& operator = (const CacheST&);
};