Skip to content

Commit

Permalink
fixed namespaced_env_cache handling of :include_community default
Browse files Browse the repository at this point in the history
  • Loading branch information
Oaphi committed Jan 15, 2025
1 parent d077021 commit 6ac8883
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/namespaced_env_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ def initialize(underlying)
@getters = {}
end

def include_community(opts)
include = opts.delete(:include_community)
include.nil? ? true : include
end

# These methods need the cache key name updating before we pass it to the underlying cache.
[:decrement, :delete, :exist?, :fetch, :increment, :read, :write, :delete_matched].each do |method|
define_method method do |name, *args, **opts, &block|
include_community = opts.delete(:include_community)
include_community = include_community(opts)
@underlying.send(method, construct_ns_key(name, include_community: include_community),
*args, **opts, &block)
end
Expand All @@ -17,7 +22,7 @@ def initialize(underlying)
# These methods need a hash of cache keys updating before we pass it to the underlying cache.
[:write_multi].each do |method|
define_method method do |hash, *args, **opts, &block|
include_community = opts.delete(:include_community)
include_community = include_community(opts)
hash = hash.map { |k, v| [construct_ns_key(k, include_community: include_community), v] }.to_h
@underlying.send(method, hash, *args, **opts, &block)
end
Expand All @@ -31,14 +36,14 @@ def initialize(underlying)
end

def read_multi(*keys, **opts)
include_community = opts.delete(:include_community)
include_community = include_community(opts)
keys = keys.map { |k| [construct_ns_key(k, include_community: include_community), k] }.to_h
results = @underlying.read_multi(*keys.keys, **opts)
results.map { |k, v| [keys[k], v] }.to_h
end

def fetch_multi(*keys, **opts, &block)
include_community = opts.delete(:include_community)
include_community = include_community(opts)
keys = keys.map { |k| construct_ns_key(k, include_community: include_community) }
@underlying.fetch_multi(*keys, **opts, &block)
end
Expand Down

0 comments on commit 6ac8883

Please sign in to comment.