Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for lambda based namespaces.

  • Loading branch information...
commit 9ec156874c3519846b90752d1bb4058fd5bff58a 1 parent 9a36942
@joshwlewis joshwlewis authored
Showing with 8 additions and 4 deletions.
  1. +7 −3 lib/dalli/client.rb
  2. +1 −1  test/test_active_support.rb
View
10 lib/dalli/client.rb
@@ -340,7 +340,7 @@ def validate_key(key)
raise ArgumentError, "key cannot be blank" if !key || key.length == 0
key = key_with_namespace(key)
if key.length > 250
- namespace_length = @options[:namespace] ? @options[:namespace].size : 0
+ namespace_length = namespace ? namespace.size : 0
max_length_before_namespace = 212 - namespace_length
key = "#{key[0, max_length_before_namespace]}:md5:#{Digest::MD5.hexdigest(key)}"
end
@@ -348,11 +348,15 @@ def validate_key(key)
end
def key_with_namespace(key)
- @options[:namespace] ? "#{@options[:namespace]}:#{key}" : key
+ namespace ? "#{namespace}:#{key}" : key
end
def key_without_namespace(key)
- @options[:namespace] ? key.sub(%r(\A#{@options[:namespace]}:), '') : key
+ namespace ? key.sub(%r(\A#{namespace}:), '') : key
+ end
+
+ def namespace
+ @options[:namespace].is_a?(Proc) ? @options[:namespace].call : @options[:namespace]
end
def normalize_options(opts)
View
2  test/test_active_support.rb
@@ -329,7 +329,7 @@ def cache_key
end
def connect
- @dalli = ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:19122', :expires_in => 10.seconds, :namespace => 'x')
+ @dalli = ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:19122', :expires_in => 10.seconds, :namespace => lambda{33.to_s(36)})
@dalli.clear
end
Please sign in to comment.
Something went wrong with that request. Please try again.