my_stuff-cache 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,9 +9,11 @@ module MyStuff
9
9
  # - MyStuff::Cache::MemoryCache
10
10
  # - MyStuff::Cache::MemcachedCache
11
11
  class Base
12
+ attr_reader :prefix
12
13
  attr_reader :logger
13
14
  def initialize options = {}
14
15
  @logger = options[:logger] || create_logger
16
+ @prefix = options[:prefix]
15
17
  end
16
18
 
17
19
  # Try to get ids from cache, falling back to the given block.
@@ -18,7 +18,12 @@ module MyStuff
18
18
 
19
19
  def get keys, options = {}
20
20
  begin
21
- results = @mc.get(keys) unless keys.empty?
21
+ if prefix.nil? || prefix.empty?
22
+ mc_keys = keys
23
+ else
24
+ mc_keys = keys.map{|x| prefix + x}
25
+ end
26
+ results = @mc.get(mc_keys) unless keys.empty?
22
27
  keys.map{|k| results[k]}
23
28
  rescue Memcached::Error => e
24
29
  logger.warn e.inspect
@@ -30,7 +35,8 @@ module MyStuff
30
35
  options[:ttl] ||= 0
31
36
  begin
32
37
  values.each do |k,v|
33
- @mc.set(k, v, options[:ttl])
38
+ prefix = self.prefix || ''
39
+ @mc.set(prefix + k, v, options[:ttl])
34
40
  end
35
41
  rescue Memcached::Error => e
36
42
  logger.warn e
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_stuff-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: