userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
fs_cache_client.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/fs/fs_cache_client.hpp
4
/// @brief @copybrief fs::FsCacheClient
5
6
#
include
<
userver
/
engine
/
io
/
sys_linux
/
inotify
.
hpp
>
7
#
include
<
userver
/
fs
/
read
.
hpp
>
8
#
include
<
userver
/
rcu
/
rcu_map
.
hpp
>
9
#
include
<
userver
/
utils
/
periodic_task
.
hpp
>
10
11
USERVER_NAMESPACE_BEGIN
12
13
namespace
fs {
14
15
/// @ingroup userver_clients
16
///
17
/// @brief Class client for storing files in memory
18
/// Usually retrieved from `components::FsCache`
19
class
FsCacheClient
final
{
20
public
:
21
/// @brief Fills the cache and starts periodic update
22
/// @param dir directory to cache files from
23
/// @param update_period time (0 - fill the cache only at startup), not used
24
/// in Linux
25
/// @param tp task processor to do filesystem operations
26
FsCacheClient
(std::string_view dir, std::chrono::milliseconds update_period, engine::TaskProcessor& tp);
27
28
/// @brief get file from memory
29
/// @param path to file
30
/// @return file info and content ; `nullptr` if no file with specified name
31
/// on FS
32
FileInfoWithDataConstPtr
TryGetFile
(std::string_view path)
const
;
33
34
/// @brief Concurrency-safe cache update
35
void
UpdateCache
();
36
37
private
:
38
#
ifdef
__linux__
39
void
InotifyWork();
40
41
void
HandleDelete(
const
std::string& path);
42
43
static
void
HandleDeleteDirectory(engine::
io
::sys_linux::Inotify& inotify,
const
std::string& path);
44
45
void
HandleCreate(
const
std::string& path);
46
47
void
HandleCreateDirectory(engine::
io
::sys_linux::Inotify& inotify,
const
std::string& path);
48
49
void
HandleCreateDirectoryBlocking(engine::
io
::sys_linux::Inotify& inotify,
const
std::string& path);
50
#
endif
51
52
const
std::string dir_;
53
const
std::chrono::milliseconds update_period_;
54
engine::TaskProcessor& tp_;
55
#
ifndef
__linux__
56
utils::PeriodicTask cache_updater_;
57
#
endif
58
rcu
::
RcuMap
<std::string,
const
fs::
FileInfoWithData
> data_;
59
60
#
ifdef
__linux__
61
engine::
Task
inotify_task_;
62
#
endif
63
};
64
65
}
// namespace fs
66
67
USERVER_NAMESPACE_END
userver
fs
fs_cache_client.hpp
Generated on
for userver by
Doxygen
1.17.0