proxygen
FilePersistentCache.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <folly/FileUtil.h>
19 #include <folly/Memory.h>
20 #include <folly/ScopeGuard.h>
21 #include <folly/json.h>
23 
24 namespace wangle {
25 
39 template<typename K, typename V, typename M = std::mutex>
40 class FilePersistentCache : public PersistentCache<K, V>,
41  private boost::noncopyable {
42  public:
44  const std::string& file,
45  std::size_t cacheCapacity,
46  std::chrono::seconds syncInterval =
47  std::chrono::duration_cast<std::chrono::seconds>(
50 
52  std::shared_ptr<folly::Executor> executor,
53  const std::string& file,
54  std::size_t cacheCapacity,
55  std::chrono::seconds syncInterval,
56  int nSyncRetries);
57 
58  ~FilePersistentCache() override {}
59 
63  folly::Optional<V> get(const K& key) override {
64  return cache_->get(key);
65  }
66 
67  void put(const K& key, const V& val) override {
68  cache_->put(key, val);
69  }
70 
71  bool remove(const K& key) override {
72  return cache_->remove(key);
73  }
74 
75  void clear(bool clearPersistence = false) override {
76  cache_->clear(clearPersistence);
77  }
78 
79  size_t size() override {
80  return cache_->size();
81  }
82 
83  void setSyncOnDestroy(bool syncOnDestroy) {
84  cache_->setSyncOnDestroy(syncOnDestroy);
85  }
86 
87  private:
89 };
90 
91 } // namespace wangle
92 
void put(const K &key, const V &val) override
LRUPersistentCache< K, V, M >::Ptr cache_
void clear(bool clearPersistence=false) override
bool remove(const K &key) override
double val
Definition: String.cpp:273
folly::Optional< V > get(const K &key) override
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
FilePersistentCache(const std::string &file, std::size_t cacheCapacity, std::chrono::seconds syncInterval=std::chrono::duration_cast< std::chrono::seconds >(client::persistence::DEFAULT_CACHE_SYNC_INTERVAL), int nSyncRetries=client::persistence::DEFAULT_CACHE_SYNC_RETRIES)
void setSyncOnDestroy(bool syncOnDestroy)
constexpr std::chrono::milliseconds DEFAULT_CACHE_SYNC_INTERVAL
const char * string
Definition: Conv.cpp:212
constexpr int DEFAULT_CACHE_SYNC_RETRIES
void clear(bool clearPersistence=false) override
void setSyncOnDestroy(bool syncOnDestroy)
void put(const K &key, const V &val) override