netshade-cache-money 0.2.5.3 → 0.2.5.4

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.
@@ -1,3 +1,5 @@
1
+ require 'digest/md5'
2
+
1
3
  module Cash
2
4
  module Accessor
3
5
  def self.included(a_module)
@@ -8,6 +10,9 @@ module Cash
8
10
  end
9
11
 
10
12
  module ClassMethods
13
+
14
+ MAX_KEY_SIZE = 250
15
+
11
16
  def fetch(keys, options = {}, &block)
12
17
  case keys
13
18
  when Array
@@ -66,7 +71,11 @@ module Cash
66
71
  end
67
72
 
68
73
  def cache_key(key)
69
- "#{name}:#{cache_config.version}/#{key.to_s.gsub(' ', '+')}"
74
+ s = "#{name}:#{cache_config.version}/#{key.to_s.gsub(' ', '+')}"
75
+ if s.size >= MAX_KEY_SIZE
76
+ s = Digest::MD5.hexdigest(s)
77
+ end
78
+ s
70
79
  end
71
80
  end
72
81
 
@@ -16,6 +16,14 @@ module Cash
16
16
  Story.fetch("yabba").should == "dabba"
17
17
  end
18
18
  end
19
+
20
+ describe "when the key size is very large" do
21
+ it "should hash the key to fit" do
22
+ k = "a" * 1024
23
+ Story.set(k, "foo")
24
+ Story.fetch(k).should == "foo"
25
+ end
26
+ end
19
27
  end
20
28
 
21
29
  describe '#fetch([...])', :shared => true do
@@ -34,6 +34,17 @@ module Cash
34
34
  Story.find(story.id, nil).should == story
35
35
  end
36
36
  end
37
+
38
+ describe "#find(id,id,id..)" do
39
+ it "accepts a larger than normal set of ids" do
40
+ st = []
41
+ 1.upto(250) do |i|
42
+ st << Story.create!
43
+ end
44
+ ids = st.collect(&:id)
45
+ Story.find(ids).should == st
46
+ end
47
+ end
37
48
  end
38
49
 
39
50
  describe 'when given nonexistent ids' do
@@ -73,6 +84,17 @@ module Cash
73
84
  end
74
85
  end
75
86
 
87
+ describe "when given a large array of ids" do
88
+ it "#finds all objects with those ids" do
89
+ st = []
90
+ 1.upto(250) do |i|
91
+ st << Story.create!
92
+ end
93
+ ids = st.collect(&:id)
94
+ Story.find(:all, :conditions => { :id => ids }).should == st
95
+ end
96
+ end
97
+
76
98
  describe '#find([])' do
77
99
  it 'returns the empty array' do
78
100
  Story.find([]).should == []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netshade-cache-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5.3
4
+ version: 0.2.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Kallen