forked from facebook/watchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymlinkTargets.h
70 lines (59 loc) · 2.11 KB
/
SymlinkTargets.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include "watchman_system.h"
#include <string>
#include "LRUCache.h"
#include "watchman_string.h"
#include "thirdparty/jansson/jansson.h"
#include "watchman_clockspec.h"
namespace watchman {
struct SymlinkTargetCacheKey {
// Path relative to the watched root
w_string relativePath;
// The modification time
w_clock_t otime;
// Computes a hash value for use in the cache map
std::size_t hashValue() const;
bool operator==(const SymlinkTargetCacheKey& other) const;
};
} // namespace watchman
namespace std {
template <>
struct hash<watchman::SymlinkTargetCacheKey> {
std::size_t operator()(watchman::SymlinkTargetCacheKey const& key) const {
return key.hashValue();
}
};
} // namespace std
namespace watchman {
class SymlinkTargetCache {
public:
using Node = LRUCache<SymlinkTargetCacheKey, w_string>::NodeType;
// Construct a cache for a given root, holding the specified
// maximum number of items, using the configured negative
// caching TTL.
SymlinkTargetCache(
const w_string& rootPath,
size_t maxItems,
std::chrono::milliseconds errorTTL);
// Obtain the content hash for the given input.
// If the result is in the cache it will return a ready future
// holding the result. Otherwise, computeHash will be invoked
// to populate the cache. Returns a future with the result
// of the lookup.
Future<std::shared_ptr<const Node>> get(const SymlinkTargetCacheKey& key);
// Read the symlink target.
// This will block the calling thread while the I/O is performed.
// Throws exceptions for any errors that may occur.
w_string readLinkImmediate(const SymlinkTargetCacheKey& key) const;
// Read the symlink target for a given input via the thread pool.
// Returns a future to operate on the result of this async operation
Future<w_string> readLink(const SymlinkTargetCacheKey& key) const;
// Returns the root path that this cache is associated with
const w_string& rootPath() const;
// Returns cache statistics
CacheStats stats() const;
private:
LRUCache<SymlinkTargetCacheKey, w_string> cache_;
w_string rootPath_;
};
} // namespace watchman