42 #include "BESInternalError.h"
45 #include "TheBESKeys.h"
47 #include "GatewayCache.h"
50 #define AT_EXIT(x) atexit((x))
57 using namespace gateway;
60 bool GatewayCache::d_enabled =
true;
62 const string GatewayCache::DIR_KEY =
"Gateway.Cache.dir";
63 const string GatewayCache::PREFIX_KEY =
"Gateway.Cache.prefix";
64 const string GatewayCache::SIZE_KEY =
"Gateway.Cache.size";
66 unsigned long GatewayCache::getCacheSizeFromConfig()
71 unsigned long size_in_megabytes = 0;
74 std::istringstream iss(size);
75 iss >> size_in_megabytes;
78 string msg =
"GatewayCache - The BES Key " + SIZE_KEY +
" is not set.";
79 BESDEBUG(
"cache", msg << endl);
82 return size_in_megabytes;
85 string GatewayCache::getCacheDirFromConfig()
92 string msg =
"GatewayCache - The BES Key " + DIR_KEY +
" is not set.";
93 BESDEBUG(
"cache", msg << endl);
100 string GatewayCache::getCachePrefixFromConfig()
109 string msg =
"GatewayCache - The BES Key " + PREFIX_KEY +
" is not set.";
110 BESDEBUG(
"cache", msg << endl);
117 GatewayCache::GatewayCache()
119 BESDEBUG(
"cache",
"GatewayCache::GatewayCache() - BEGIN" << endl);
121 string cacheDir = getCacheDirFromConfig();
122 string cachePrefix = getCachePrefixFromConfig();
123 unsigned long cacheSizeMbytes = getCacheSizeFromConfig();
126 "GatewayCache() - Cache configuration params: " << cacheDir <<
", " << cachePrefix <<
", " << cacheSizeMbytes << endl);
128 initialize(cacheDir, cachePrefix, cacheSizeMbytes);
130 BESDEBUG(
"cache",
"GatewayCache::GatewayCache() - END" << endl);
133 GatewayCache::GatewayCache(
const string &cache_dir,
const string &prefix,
unsigned long long size)
135 BESDEBUG(
"cache",
"GatewayCache::GatewayCache() - BEGIN" << endl);
139 BESDEBUG(
"cache",
"GatewayCache::GatewayCache() - END" << endl);
145 if (d_enabled && d_instance == 0) {
147 d_instance =
new GatewayCache(cache_dir, cache_file_prefix, max_cache_size);
152 BESDEBUG(
"cache",
"GatewayCache::"<<__func__ <<
"() - " <<
"Cache is DISABLED"<< endl);
155 AT_EXIT(delete_instance);
157 BESDEBUG(
"cache",
"GatewayCache::"<<__func__ <<
"() - " <<
"Cache is ENABLED"<< endl);
171 if (d_enabled && d_instance == 0) {
178 BESDEBUG(
"cache",
"GatewayCache::"<<__func__ <<
"() - " <<
"Cache is DISABLED"<< endl);
181 AT_EXIT(delete_instance);
183 BESDEBUG(
"cache",
"GatewayCache::" << __func__ <<
"() - " <<
"Cache is ENABLED"<< endl);
188 "[ERROR] GatewayCache::get_instance(): Failed to obtain cache! msg: " << bie.
get_message() << endl);