Skip to content

Commit 3bb9ea9

Browse files
Jimmy Lufacebook-github-bot
authored andcommitted
Update HybridCache doc to remove mention of "onReady()"
Summary: We no longer let users directly attach a callback to onReady(), which is unsafe due to thread handle count. This caused some confusion in the PR: #239 This diff cleans up the comments Reviewed By: jaesoo-fb Differential Revision: D46446698 fbshipit-source-id: fb26a7a731a80cf7f5158b8f2ebaa261bb72b62b
1 parent b3e2dd4 commit 3bb9ea9

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

website/docs/Cache_Library_User_Guides/HybridCache.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,17 @@ This indicates that the handle is still waiting for the item to be pulled into D
6060
6161
To check whether a Handle is ready, call the `isReady()` method via the Handle.
6262
63-
If the application can tolerate the latency of accessing NVM for some of your accesses from cache, there is not a lot of change that is needed on how you use cachelib today. However, if you are impacted by latency, you can do the following:
63+
If the application can tolerate the latency of accessing NVM for some of your accesses from cache, there is not a lot of change that is needed on how you use cachelib today.
6464
65-
1. By default, if you don't change your existing cachelib code, dereferencing a handle that is not ready or doing any check on the result of the handle will **block** until it becomes ready. When it is blocking, if you are in a fiber context, it puts the fiber to sleep.
66-
2. Set a callback to be executed `onReady()`. The callback will be executed when the handle is ready or immediately if the handle is already ready.
67-
3. Get a `folly::SemiFuture` on the handle by calling the `toSemiFuture()` method.
68-
4. Pass the handle in its current state to another execution context that can then execute your code when the handle becomes ready.
65+
However, if you are impacted by latency, you can do the following:
66+
1. Get a `folly::SemiFuture` on the handle by calling the `toSemiFuture()` method.
67+
2. You may attach any additional logic to be executed on the item via SemiFuture's `defer()` callback.
68+
3. Pass the SemiFuture to an execution context (e.g. folly's EventBase) that can then execute your code when the handle becomes ready.
6969
70-
The following code snipper highlights the various techniques.
70+
The following code snippet highlights the various techniques.
7171
7272
7373
```cpp
74-
auto processItem = [](Handle h) {
75-
// my processing logic.
76-
};
77-
7874
/* Accessing item on a fiber or in blocking way with NvmCache */
7975
auto handle = cache.find("foobar");
8076
@@ -87,9 +83,15 @@ if (handle) {
8783
auto handle = cache.find("foobar");
8884
auto semiFuture = handle.toSemiFuture();
8985
90-
/* Accessing an item and setting a onReady callback */
91-
auto handle = cache.find("foobar");
92-
handle.onReady(processItem); // process the item when the handle becomes ready
86+
/* Attach (optional) callback that is invoked when semifuture is executed */
87+
auto sf = std::move(semiFuture).deferValue([] (const auto itemHandle) {
88+
/* Do something with the item */
89+
});
90+
91+
/* Schedule semi future to be executed async, when the item is ready */
92+
std::move(semiFuture).via(
93+
folly::Executor::getKeepAliveToken(
94+
folly::EventBaseManager::get()->getExistingEventBase()));
9395
```
9496

9597

0 commit comments

Comments
 (0)