join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
cache.hpp
Go to the documentation of this file.
1
25#ifndef __JOIN_CACHE_HPP__
26#define __JOIN_CACHE_HPP__
27
28// libjoin.
29#include <join/mutex.hpp>
30
31// C++.
32#include <string>
33#include <memory>
34#include <map>
35
36// C.
37#include <sys/stat.h>
38
39namespace join
40{
44 class Cache
45 {
46 public:
50 Cache () = default;
51
56 Cache (const Cache& other) = delete;
57
63 Cache& operator= (const Cache& other) = delete;
64
69 Cache (Cache&& other) = delete;
70
76 Cache& operator= (Cache&& other) = delete;
77
81 ~Cache ();
82
89 void* get (const std::string &fileName, struct stat &sbuf);
90
95 void remove (const std::string &fileName);
96
100 void clear ();
101
105 size_t size ();
106
107 protected:
112 {
113 off_t size;
114 struct timespec modifTime;
115 void *addr;
116 };
117
119 std::map <std::string, std::unique_ptr <CacheEntry>> _entries;
120
123 };
124}
125
126#endif
File cache.
Definition cache.hpp:45
Cache(Cache &&other)=delete
create instance by move.
Mutex _mutex
protection mutex for the cache map.
Definition cache.hpp:122
void remove(const std::string &fileName)
remove a cached entry identified by the given file name.
Definition cache.cpp:101
Cache & operator=(const Cache &other)=delete
assign instance by copy.
void * get(const std::string &fileName, struct stat &sbuf)
get or create the cache entry for the given file.
Definition cache.cpp:52
void clear()
clear all cached entries.
Definition cache.cpp:117
Cache()=default
create instance.
size_t size()
get number of cache entries.
Definition cache.cpp:133
Cache(const Cache &other)=delete
create instance by copy.
std::map< std::string, std::unique_ptr< CacheEntry > > _entries
cached entries map.
Definition cache.hpp:119
~Cache()
destroy instance.
Definition cache.cpp:43
class used to protect shared data from being simultaneously accessed by multiple threads.
Definition mutex.hpp:37
Definition acceptor.hpp:32
cache entry.
Definition cache.hpp:112
off_t size
Definition cache.hpp:113
struct timespec modifTime
Definition cache.hpp:114
void * addr
Definition cache.hpp:115