29 #ifndef BESFileLockingCache_h_ 30 #define BESFileLockingCache_h_ 1 40 #define USE_GET_SHARED_LOCK 1 46 unsigned long long size;
50 typedef std::list<cache_entry> CacheFiles;
88 friend class FileLockingCacheTest;
91 static const char DAP_CACHE_CHAR =
'#';
102 unsigned long long d_max_cache_size_in_bytes;
105 unsigned long long d_target_size;
112 typedef std::multimap<string, int> FilesAndLockDescriptors;
113 FilesAndLockDescriptors d_locks;
115 bool m_check_ctor_params();
116 bool m_initialize_cache_info();
118 unsigned long long m_collect_cache_dir_info(CacheFiles &contents);
120 void m_record_descriptor(
const string &file,
int fd);
121 int m_remove_descriptor(
const string &file);
122 #if USE_GET_SHARED_LOCK 123 int m_find_descriptor(
const string &file);
131 BESFileLockingCache(): d_cache_enabled(
true), d_cache_dir(
""), d_prefix(
""), d_max_cache_size_in_bytes(0),
132 d_target_size(0), d_cache_info(
""), d_cache_info_fd(-1) {};
134 BESFileLockingCache(
const string &cache_dir,
const string &prefix,
unsigned long long size);
138 if (d_cache_info_fd != -1) {
139 close(d_cache_info_fd);
140 d_cache_info_fd = -1;
144 void initialize(
const string &cache_dir,
const string &prefix,
unsigned long long size);
160 virtual bool cache_too_big(
unsigned long long current_size)
const;
184 return d_cache_enabled;
190 d_cache_enabled =
false;
196 d_cache_enabled =
true;
199 virtual void dump(ostream &strm)
const;
202 #endif // BESFileLockingCache_h_ virtual void unlock_cache()
virtual bool cache_too_big(unsigned long long current_size) const
look at the cache size; is it too large? Look at the cache size and see if it is too big...
virtual bool create_and_lock(const string &target, int &fd)
Create a file in the cache and lock it for write access.
void disable()
Disable the cache.
virtual unsigned long long get_cache_size()
Get the cache size. Read the size information from the cache info file and return it...
Implementation of a caching mechanism for compressed data.
Base object for bes objects.
static bool dir_exists(const string &dir)
virtual void purge_file(const string &file)
Purge a single file from the cache.
const string get_cache_directory()
virtual void lock_cache_write()
virtual void dump(ostream &strm) const
dumps information about this object
virtual string get_cache_file_name(const string &src, bool mangle=true)
void enable()
Enabel the cache.
virtual bool get_read_lock(const string &target, int &fd)
Get a read-only lock on the file if it exists.
const string get_cache_file_prefix()
virtual void update_and_purge(const string &new_file)
Purge files from the cache.
virtual unsigned long long update_cache_info(const string &target)
Update the cache info file to include 'target'.
virtual void lock_cache_read()
virtual void exclusive_to_shared_lock(int fd)
Transfer from an exclusive lock to a shared lock.
virtual void unlock_and_close(const string &target)