diff --git a/server/modules/filter/cache/CMakeLists.txt b/server/modules/filter/cache/CMakeLists.txt index 69ea3e697..2c785973a 100644 --- a/server/modules/filter/cache/CMakeLists.txt +++ b/server/modules/filter/cache/CMakeLists.txt @@ -1,5 +1,5 @@ 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) set_target_properties(cache PROPERTIES VERSION "1.0.0") set_target_properties(cache PROPERTIES LINK_FLAGS -Wl,-z,defs) diff --git a/server/modules/filter/cache/cachest.cc b/server/modules/filter/cache/cachest.cc new file mode 100644 index 000000000..b2fcdbc34 --- /dev/null +++ b/server/modules/filter/cache/cachest.cc @@ -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); +} diff --git a/server/modules/filter/cache/cachest.h b/server/modules/filter/cache/cachest.h new file mode 100644 index 000000000..67a1f9e39 --- /dev/null +++ b/server/modules/filter/cache/cachest.h @@ -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 +#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&); +};