Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize Memory Cache API: Align delete operation with KV API #3553

Draft
wants to merge 2 commits into
base: mar/memory-cache-delete
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/workerd/api/memory-cache.c++
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,15 @@ jsg::Promise<jsg::JsRef<jsg::JsValue>> MemoryCache::read(jsg::Lock& js,
}
}

void MemoryCache::delete_(jsg::Lock& js, jsg::NonCoercible<kj::String> key) {
// Ignore operations on keys exceeding key max size.
jsg::Promise<void> MemoryCache::delete_(jsg::Lock& js, jsg::NonCoercible<kj::String> key) {
if (key.value.size() > MAX_KEY_SIZE) {
return;
return js.rejectedPromise<void>(js.rangeError("Key too large."_kj));
}

auto deleteSpan = IoContext::current().makeTraceSpan("memory_cache_delete"_kjc);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with volatile cache/memory cache, but except for acquiring the lock in SharedMemoryCache::Use::delete_() this looks like a mostly synchronous operation here right? Not sure if we should add a span here since we'd expect the operation to complete very quickly; we'd also need to add some internal plumbing to support/document the span.


cacheUse.delete_(key.value);
return js.resolvedPromise();
}

// ======================================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/memory-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ class MemoryCache: public jsg::Object {
jsg::Optional<FallbackFunction> optionalFallback);

// Delete a value from the cache.
void delete_(jsg::Lock& js, jsg::NonCoercible<kj::String> key);
jsg::Promise<void> delete_(jsg::Lock& js, jsg::NonCoercible<kj::String> key);

JSG_RESOURCE_TYPE(MemoryCache) {
JSG_METHOD(read);
Expand Down
Loading