Skip to content

Commit 31f1370

Browse files
Jaesoo Leefacebook-github-bot
authored andcommitted
Edit Cache_persistence.md using inpage editor
Summary: This diff has been automatically generated by the inpage editor. If you want to update this diff, go via the preview link inside the static docs section below. Please ensure you are editing the same page that was used to create this diff. Reviewed By: haowu14 Differential Revision: D41747410 fbshipit-source-id: 0be8e8dd60f1ed3466bdfeac15618a4a2b429a03
1 parent 94eaded commit 31f1370

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

website/docs/Cache_Library_User_Guides/Cache_persistence.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ enum class ShutDownRes { kSuccess = 0, kFileDeleted, kFailedWrite }
5353
5454
## Restore a persistent cache
5555
56-
On start up, try to use the following constructor to attach to your previous instance of cache. Upon failure, you can create a new one like before. A common pattern that many cachelib users do is to try to always attach on startup; if attach fails, which will throw an exception, catch the exception and then try to create a new cache.
56+
On start up, try to use the following constructor to attach to your previous instance of cache. Upon failure, you can create a new one like before. A common pattern that many cachelib users do is to try to always attach on startup; if attach fails, which will throw an exception, catch the exception and then try to create a new cache. Also, please note that the pools should not be added again if the attach has been succeeded.
5757
5858
5959
```cpp
@@ -62,10 +62,12 @@ config.setCacheSize(/* this must be the same size you specified before */);
6262
config.enableCachePersistence(
6363
/* this must be the same cache directory you specified before */);
6464
65+
bool attached = false;
6566
std::unique_ptr<Cache> cache;
6667
try {
6768
cache = std::make_unique<Cache>(Cache::SharedMemAttach, config);
6869
// Cache is now restored
70+
attached = true;
6971
} catch (const std::exception& ex) {
7072
// Attaching failed. Create a new one but make sure that
7173
// the old cache is destroyed before creating a new one.
@@ -75,6 +77,11 @@ try {
7577
std::cerr << "Couldn't attach to cache: " << ex.what() << std::endl;
7678
cache = std::make_unique<Cache>(Cache::SharedMemNew, config);
7779
}
80+
81+
if (!attached) {
82+
// Add pool only if the cache is not restored above
83+
cache->addPool("default", cache->getCacheMemoryStats().cacheSize);
84+
}
7885
```
7986

8087

0 commit comments

Comments
 (0)