185
66
cache = vmemcache_new();
67
if (vmemcache_add(cache, "/daxfs")) {
68
fprintf(stderr, "error: vmemcache_add: %s\n",
69
vmemcache_errormsg());
70
exit(1);
71
}
72
73
// Query a non-existent key
74
get("meow");
75
76
// Insert then query
77
vmemcache_put(cache, STR_AND_LEN("bark"),
78
STR_AND_LEN("Lorem ipsum"));
79
get("bark");
80
81
// Install an on-miss handler
82
vmemcache_callback_on_miss(cache, on_miss, 0);
83
get("meow");
84
85
vmemcache_delete(cache);
• Line 66: Creates a new instance of vmemcache with default values for
eviction_policy and extent_size.
• Line 67: Calls the vmemcache_add() function to associate cache with a
given path.
• Line 74: Calls the get() function to query on an existing key. This
function calls the vmemcache_get() function with error checking for
success/failure of the function.
• Line 77: Calls vmemcache_put() to insert a new key.
• Line 82: Adds an on-miss callback handler to insert the key “meow”
into the cache.
• Line 83: Retrieves the key “meow” using the get() function.
• Line 85: Deletes the vmemcache instance.
Chapter 10 Volatile Use of persistent MeMory
Précédent

- 209/457

Suivant