You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: website/docs/Cache_Library_User_Guides/HybridCache.md
+15-13Lines changed: 15 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,21 +60,17 @@ This indicates that the handle is still waiting for the item to be pulled into D
60
60
61
61
To check whether a Handle is ready, call the `isReady()` method via the Handle.
62
62
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.
64
64
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.
69
69
70
-
The following code snipper highlights the various techniques.
70
+
The following code snippet highlights the various techniques.
71
71
72
72
73
73
```cpp
74
-
auto processItem = [](Handle h) {
75
-
// my processing logic.
76
-
};
77
-
78
74
/* Accessing item on a fiber or in blocking way with NvmCache */
79
75
auto handle = cache.find("foobar");
80
76
@@ -87,9 +83,15 @@ if (handle) {
87
83
auto handle = cache.find("foobar");
88
84
auto semiFuture = handle.toSemiFuture();
89
85
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 */
0 commit comments