diff --git a/server/modules/filter/cache/cache_storage_api.h b/server/modules/filter/cache/cache_storage_api.h index e5bfeacb5..33d911e2e 100644 --- a/server/modules/filter/cache/cache_storage_api.h +++ b/server/modules/filter/cache/cache_storage_api.h @@ -37,6 +37,12 @@ typedef enum cache_flags CACHE_FLAGS_INCLUDE_STALE = 0x01, } cache_flags_t; +typedef enum cache_thread_model +{ + CACHE_THREAD_MODEL_ST = 0x1, + CACHE_THREAD_MODEL_MT = 0x2, +} cache_thread_model_t; + typedef void* CACHE_STORAGE; enum @@ -58,6 +64,10 @@ typedef struct cache_storage_api * create the actual storage, initialize it and prepare to put and get * cache items. * + * @param model Whether the storage will be used in a single thread or + * multi thread context. In the latter case the storage must + * perform thread synchronization as appropriate, in the former + * case it need not. * @param name The name of the cache instance. * @param ttl Time to live; number of seconds the value is valid. * @param argc The number of elements in the argv array. @@ -66,7 +76,8 @@ typedef struct cache_storage_api * @return A new cache instance, or NULL if the instance could not be * created. */ - CACHE_STORAGE* (*createInstance)(const char *name, + CACHE_STORAGE* (*createInstance)(cache_thread_model_t model, + const char *name, uint32_t ttl, int argc, char* argv[]); diff --git a/server/modules/filter/cache/cachefilter.h b/server/modules/filter/cache/cachefilter.h index 6fcdca1d1..86edc6292 100644 --- a/server/modules/filter/cache/cachefilter.h +++ b/server/modules/filter/cache/cachefilter.h @@ -16,6 +16,7 @@ #include #include +#include #include #include #include "rules.h" diff --git a/server/modules/filter/cache/cachemt.cc b/server/modules/filter/cache/cachemt.cc index 6fcc0e5cf..ffdc14a5c 100644 --- a/server/modules/filter/cache/cachemt.cc +++ b/server/modules/filter/cache/cachemt.cc @@ -12,8 +12,6 @@ */ #include "cachemt.h" -#include -#include #include "storage.h" #include "storagefactory.h" @@ -46,7 +44,7 @@ CacheMT* CacheMT::Create(const char* zName, CACHE_CONFIG& config) int argc = config.storage_argc; char** argv = config.storage_argv; - Storage* pStorage = pFactory->createStorage(zName, ttl, argc, argv); + Storage* pStorage = pFactory->createStorage(CACHE_THREAD_MODEL_MT, zName, ttl, argc, argv); if (pStorage) { diff --git a/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.cc b/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.cc index 5c32a9b2e..1e619c737 100644 --- a/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.cc +++ b/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.cc @@ -23,7 +23,10 @@ bool initialize() return RocksDBStorage::Initialize(); } -CACHE_STORAGE* createInstance(const char* zName, uint32_t ttl, int argc, char* argv[]) +CACHE_STORAGE* createInstance(cache_thread_model_t, // Ignored, RocksDB always MT safe. + const char* zName, + uint32_t ttl, + int argc, char* argv[]) { ss_dassert(zName); diff --git a/server/modules/filter/cache/storagefactory.cc b/server/modules/filter/cache/storagefactory.cc index 09e2f984a..8dd49f0e4 100644 --- a/server/modules/filter/cache/storagefactory.cc +++ b/server/modules/filter/cache/storagefactory.cc @@ -131,7 +131,8 @@ StorageFactory* StorageFactory::Open(const char* zName) return pFactory; } -Storage* StorageFactory::createStorage(const char* zName, +Storage* StorageFactory::createStorage(cache_thread_model_t model, + const char* zName, uint32_t ttl, int argc, char* argv[]) { @@ -139,7 +140,7 @@ Storage* StorageFactory::createStorage(const char* zName, ss_dassert(m_pApi); Storage* pStorage = 0; - CACHE_STORAGE* pRawStorage = m_pApi->createInstance(zName, ttl, argc, argv); + CACHE_STORAGE* pRawStorage = m_pApi->createInstance(model, zName, ttl, argc, argv); if (pRawStorage) { diff --git a/server/modules/filter/cache/storagefactory.h b/server/modules/filter/cache/storagefactory.h index e87f57742..f2c1a9d22 100644 --- a/server/modules/filter/cache/storagefactory.h +++ b/server/modules/filter/cache/storagefactory.h @@ -26,7 +26,8 @@ public: static StorageFactory* Open(const char* zName); - Storage* createStorage(const char* zName, + Storage* createStorage(cache_thread_model_t model, + const char* zName, uint32_t ttl, int argc, char* argv[]);