DEV: Add usage example for anon cache cookie registration (#32283)

Adding an example for the plugin api `register_anonymous_cache_key`.
This commit is contained in:
Natalie Tay
2025-04-14 21:03:05 +08:00
committed by GitHub
parent f0057c7353
commit d1ce861a6b
+5
View File
@@ -103,6 +103,11 @@ class Plugin::Instance
@idx = 0
end
# Keys can only be lowercase letters
# Example usage:
# plugin.register_anonymous_cache_key :onlylowercase do
# @request.cookies["cookie_name"].present? ? "1" : "0"
# end
def register_anonymous_cache_key(key, &block)
key_method = "key_#{key}"
add_to_class(Middleware::AnonymousCache::Helper, key_method, &block)