@@ -73,6 +73,92 @@ describe LuckyCache::MemoryStore do
7373 friends.map(& .title).should contain(" learn about cash" )
7474 end
7575
76+ it " caches an array of strings" do
77+ cache = LuckyCache ::MemoryStore .new
78+ counter = 0
79+ cache.fetch(" tags" , as: Array (String )) do
80+ counter += 1
81+ [" foo" , " bar" , " baz" ]
82+ end
83+ result = cache.fetch(" tags" , as: Array (String )) do
84+ counter += 1
85+ [" foo" , " bar" , " baz" ]
86+ end
87+
88+ result.should be_a(Array (String ))
89+ counter.should eq(1 )
90+ result.size.should eq(3 )
91+ result.should eq([" foo" , " bar" , " baz" ])
92+ end
93+
94+ it " caches an array of Int32" do
95+ cache = LuckyCache ::MemoryStore .new
96+ counter = 0
97+ cache.fetch(" numbers" , as: Array (Int32 )) do
98+ counter += 1
99+ [1 , 2 , 3 ]
100+ end
101+ result = cache.fetch(" numbers" , as: Array (Int32 )) do
102+ counter += 1
103+ [1 , 2 , 3 ]
104+ end
105+
106+ result.should be_a(Array (Int32 ))
107+ counter.should eq(1 )
108+ result.should eq([1 , 2 , 3 ])
109+ end
110+
111+ it " caches an array of Int64" do
112+ cache = LuckyCache ::MemoryStore .new
113+ counter = 0
114+ cache.fetch(" big_numbers" , as: Array (Int64 )) do
115+ counter += 1
116+ [100 _i64 , 200 _i64 ]
117+ end
118+ result = cache.fetch(" big_numbers" , as: Array (Int64 )) do
119+ counter += 1
120+ [100 _i64 , 200 _i64 ]
121+ end
122+
123+ result.should be_a(Array (Int64 ))
124+ counter.should eq(1 )
125+ result.should eq([100 _i64 , 200 _i64 ])
126+ end
127+
128+ it " caches an array of Float64" do
129+ cache = LuckyCache ::MemoryStore .new
130+ counter = 0
131+ cache.fetch(" scores" , as: Array (Float64 )) do
132+ counter += 1
133+ [1.5 , 2.7 , 3.9 ]
134+ end
135+ result = cache.fetch(" scores" , as: Array (Float64 )) do
136+ counter += 1
137+ [1.5 , 2.7 , 3.9 ]
138+ end
139+
140+ result.should be_a(Array (Float64 ))
141+ counter.should eq(1 )
142+ result.should eq([1.5 , 2.7 , 3.9 ])
143+ end
144+
145+ it " caches an array of Bool" do
146+ cache = LuckyCache ::MemoryStore .new
147+ counter = 0
148+ cache.fetch(" flags" , as: Array (Bool )) do
149+ counter += 1
150+ [true , false , true ]
151+ end
152+ result = cache.fetch(" flags" , as: Array (Bool )) do
153+ counter += 1
154+ [true , false , true ]
155+ end
156+
157+ result.should be_a(Array (Bool ))
158+ counter.should eq(1 )
159+ result.should eq([true , false , true ])
160+ end
161+
76162 it " caches basic types" do
77163 cache = LuckyCache ::MemoryStore .new
78164 str = cache.fetch(" string:key" , as: String ) { " test" }
0 commit comments