rails-cache-tags 1.0.0 → 1.1.0
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.
- data/.gitignore +2 -1
- data/Appraisals +11 -0
- data/Rakefile +1 -0
- data/lib/rails/cache/tag.rb +7 -9
- data/lib/rails/cache/tags/store.rb +2 -0
- data/lib/rails/cache/tags/version.rb +1 -1
- data/lib/rails-cache-tags.rb +7 -7
- data/rails-cache-tags.gemspec +2 -2
- data/test/cache_tags_test.rb +17 -1
- data/test/caching_test.rb +47 -277
- metadata +27 -20
data/.gitignore
CHANGED
data/Appraisals
ADDED
data/Rakefile
CHANGED
data/lib/rails/cache/tag.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
require "active_support/cache"
|
2
|
+
|
1
3
|
module Rails
|
2
4
|
module Cache
|
3
5
|
class Tag #:nodoc:all:
|
4
6
|
KEY_PREFIX = '_tags'
|
5
7
|
|
6
8
|
class << self
|
7
|
-
# {:post => ['1', '2', '3']} => [Tag(post
|
8
|
-
# {:post => 1, :user => 2} => [Tag(post
|
9
|
-
# ['post
|
9
|
+
# {:post => ['1', '2', '3']} => [Tag(post/1), Tag(post/2), Tag(post/3)]
|
10
|
+
# {:post => 1, :user => 2} => [Tag(post/1), Tag(user/2)]
|
11
|
+
# ['post/1', 'post/2', 'post/3'] => [Tag(post/1), Tag(post/2), Tag(post/3)]
|
10
12
|
def build_tags(names)
|
11
13
|
case names
|
12
14
|
when NilClass then nil
|
@@ -22,13 +24,9 @@ module Rails
|
|
22
24
|
|
23
25
|
attr_reader :name
|
24
26
|
|
25
|
-
# Tag constructor
|
27
|
+
# Tag constructor
|
26
28
|
def initialize(name)
|
27
|
-
@name =
|
28
|
-
when String, Symbol then name
|
29
|
-
when Array then name.join(':')
|
30
|
-
else raise ArgumentError
|
31
|
-
end
|
29
|
+
@name = ActiveSupport::Cache.expand_cache_key name
|
32
30
|
end
|
33
31
|
|
34
32
|
# real cache key
|
data/lib/rails-cache-tags.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "active_support/cache"
|
2
2
|
|
3
|
+
require "action_controller"
|
4
|
+
|
3
5
|
require "rails/cache/tag"
|
4
6
|
require "rails/cache/tags/store"
|
5
7
|
|
@@ -15,13 +17,11 @@ module ActiveSupport
|
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
return unless cache_configured?
|
20
|
+
class ActionController::Base < ActionController::Metal
|
21
|
+
def expire_fragments_by_tags *args
|
22
|
+
return unless cache_configured?
|
22
23
|
|
23
|
-
|
24
|
-
end
|
25
|
-
alias expire_fragments_by_tag expire_fragments_by_tags
|
24
|
+
cache_store.delete_tag *args
|
26
25
|
end
|
26
|
+
alias expire_fragments_by_tag expire_fragments_by_tags
|
27
27
|
end
|
data/rails-cache-tags.gemspec
CHANGED
@@ -14,9 +14,9 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.require_paths = %W(lib)
|
15
15
|
gem.version = Rails::Cache::Tags::VERSION
|
16
16
|
|
17
|
-
gem.add_dependency "
|
18
|
-
gem.add_dependency "actionpack", ">= 3.0"
|
17
|
+
gem.add_dependency "rails", ">= 3.0"
|
19
18
|
|
19
|
+
gem.add_development_dependency 'appraisal'
|
20
20
|
gem.add_development_dependency 'minitest', '~> 3.2'
|
21
21
|
gem.add_development_dependency 'memcache-client'
|
22
22
|
gem.add_development_dependency 'rack'
|
data/test/cache_tags_test.rb
CHANGED
@@ -57,6 +57,8 @@ module CacheTagsBehavior
|
|
57
57
|
|
58
58
|
def test_exists_with_tags
|
59
59
|
@cache.write("foo", "bar", :tags => "baz")
|
60
|
+
assert_equal @cache.exist?("foo"), true
|
61
|
+
|
60
62
|
@cache.delete_tag("baz")
|
61
63
|
|
62
64
|
assert_equal @cache.exist?("foo"), false
|
@@ -67,12 +69,26 @@ module CacheTagsBehavior
|
|
67
69
|
assert_equal 'bar', @cache.read('foo')
|
68
70
|
end
|
69
71
|
|
70
|
-
def
|
72
|
+
def test_read_and_write_with_hash_of_tags
|
71
73
|
@cache.write("foo", "bar", :tags => {:baz => 1})
|
74
|
+
assert_equal 'bar', @cache.read('foo')
|
75
|
+
|
72
76
|
@cache.delete_tag :baz => 1
|
73
77
|
|
74
78
|
assert_nil @cache.read('foo')
|
75
79
|
end
|
80
|
+
|
81
|
+
def test_read_and_write_with_tags_array_of_objects
|
82
|
+
tag1 = 1.day.ago
|
83
|
+
tag2 = 2.days.ago
|
84
|
+
|
85
|
+
@cache.write("foo", "bar", :tags => [tag1, tag2])
|
86
|
+
assert_equal 'bar', @cache.read('foo')
|
87
|
+
|
88
|
+
@cache.delete_tag tag2
|
89
|
+
|
90
|
+
assert_nil @cache.read('foo')
|
91
|
+
end
|
76
92
|
end
|
77
93
|
|
78
94
|
[FileStoreTest, MemoryStoreTest, MemCacheStoreTest].each do |klass|
|
data/test/caching_test.rb
CHANGED
@@ -14,10 +14,8 @@ class CacheKeyTest < ActiveSupport::TestCase
|
|
14
14
|
ENV['RAILS_CACHE_ID'] = 'c99'
|
15
15
|
assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo)
|
16
16
|
assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key([:foo])
|
17
|
-
assert_equal 'c99/foo/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar])
|
18
17
|
assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key(:foo, :nm)
|
19
18
|
assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key([:foo], :nm)
|
20
|
-
assert_equal 'nm/c99/foo/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar], :nm)
|
21
19
|
ensure
|
22
20
|
ENV['RAILS_CACHE_ID'] = nil
|
23
21
|
end
|
@@ -43,7 +41,7 @@ class CacheKeyTest < ActiveSupport::TestCase
|
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
|
-
def
|
44
|
+
def test_respond_to_cache_key
|
47
45
|
key = 'foo'
|
48
46
|
def key.cache_key
|
49
47
|
:foo_key
|
@@ -51,25 +49,6 @@ class CacheKeyTest < ActiveSupport::TestCase
|
|
51
49
|
assert_equal 'foo_key', ActiveSupport::Cache.expand_cache_key(key)
|
52
50
|
end
|
53
51
|
|
54
|
-
def test_expand_cache_key_array_with_something_that_responds_to_cache_key
|
55
|
-
key = 'foo'
|
56
|
-
def key.cache_key
|
57
|
-
:foo_key
|
58
|
-
end
|
59
|
-
assert_equal 'foo_key', ActiveSupport::Cache.expand_cache_key([key])
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_expand_cache_key_of_nil
|
63
|
-
assert_equal '', ActiveSupport::Cache.expand_cache_key(nil)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_expand_cache_key_of_false
|
67
|
-
assert_equal 'false', ActiveSupport::Cache.expand_cache_key(false)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_expand_cache_key_of_true
|
71
|
-
assert_equal 'true', ActiveSupport::Cache.expand_cache_key(true)
|
72
|
-
end
|
73
52
|
end
|
74
53
|
|
75
54
|
class CacheStoreSettingTest < ActiveSupport::TestCase
|
@@ -142,8 +121,8 @@ class CacheStoreNamespaceTest < ActiveSupport::TestCase
|
|
142
121
|
cache.write("foo", "bar")
|
143
122
|
cache.write("fu", "baz")
|
144
123
|
cache.delete_matched(/^fo/)
|
145
|
-
|
146
|
-
|
124
|
+
assert_equal false, cache.exist?("foo")
|
125
|
+
assert_equal true, cache.exist?("fu")
|
147
126
|
end
|
148
127
|
|
149
128
|
def test_delete_matched_key
|
@@ -151,15 +130,15 @@ class CacheStoreNamespaceTest < ActiveSupport::TestCase
|
|
151
130
|
cache.write("foo", "bar")
|
152
131
|
cache.write("fu", "baz")
|
153
132
|
cache.delete_matched(/OO/i)
|
154
|
-
|
155
|
-
|
133
|
+
assert_equal false, cache.exist?("foo")
|
134
|
+
assert_equal true, cache.exist?("fu")
|
156
135
|
end
|
157
136
|
end
|
158
137
|
|
159
138
|
# Tests the base functionality that should be identical across all cache stores.
|
160
139
|
module CacheStoreBehavior
|
161
140
|
def test_should_read_and_write_strings
|
162
|
-
|
141
|
+
assert_equal true, @cache.write('foo', 'bar')
|
163
142
|
assert_equal 'bar', @cache.read('foo')
|
164
143
|
end
|
165
144
|
|
@@ -194,40 +173,20 @@ module CacheStoreBehavior
|
|
194
173
|
end
|
195
174
|
|
196
175
|
def test_should_read_and_write_hash
|
197
|
-
|
176
|
+
assert_equal true, @cache.write('foo', {:a => "b"})
|
198
177
|
assert_equal({:a => "b"}, @cache.read('foo'))
|
199
178
|
end
|
200
179
|
|
201
180
|
def test_should_read_and_write_integer
|
202
|
-
|
181
|
+
assert_equal true, @cache.write('foo', 1)
|
203
182
|
assert_equal 1, @cache.read('foo')
|
204
183
|
end
|
205
184
|
|
206
185
|
def test_should_read_and_write_nil
|
207
|
-
|
186
|
+
assert_equal true, @cache.write('foo', nil)
|
208
187
|
assert_equal nil, @cache.read('foo')
|
209
188
|
end
|
210
189
|
|
211
|
-
def test_should_read_and_write_false
|
212
|
-
assert @cache.write('foo', false)
|
213
|
-
assert_equal false, @cache.read('foo')
|
214
|
-
end
|
215
|
-
|
216
|
-
def test_should_read_cached_numeric_from_previous_rails_versions
|
217
|
-
@old_cache = ActiveSupport::Cache::Entry.create( 1, Time.now )
|
218
|
-
assert_equal( 1, @old_cache.value )
|
219
|
-
end
|
220
|
-
|
221
|
-
def test_should_read_cached_hash_from_previous_rails_versions
|
222
|
-
@old_cache = ActiveSupport::Cache::Entry.create( {}, Time.now )
|
223
|
-
assert_equal( {}, @old_cache.value )
|
224
|
-
end
|
225
|
-
|
226
|
-
def test_should_read_cached_string_from_previous_rails_versions
|
227
|
-
@old_cache = ActiveSupport::Cache::Entry.create( 'string', Time.now )
|
228
|
-
assert_equal( 'string', @old_cache.value )
|
229
|
-
end
|
230
|
-
|
231
190
|
def test_read_multi
|
232
191
|
@cache.write('foo', 'bar')
|
233
192
|
@cache.write('fu', 'baz')
|
@@ -243,13 +202,6 @@ module CacheStoreBehavior
|
|
243
202
|
assert_equal({"fu" => "baz"}, @cache.read_multi('foo', 'fu'))
|
244
203
|
end
|
245
204
|
|
246
|
-
def test_read_and_write_compressed_small_data
|
247
|
-
@cache.write('foo', 'bar', :compress => true)
|
248
|
-
raw_value = @cache.send(:read_entry, 'foo', {}).raw_value
|
249
|
-
assert_equal 'bar', @cache.read('foo')
|
250
|
-
assert_equal 'bar', Marshal.load(raw_value)
|
251
|
-
end
|
252
|
-
|
253
205
|
def test_read_and_write_compressed_large_data
|
254
206
|
@cache.write('foo', 'bar', :compress => true, :compress_threshold => 2)
|
255
207
|
raw_value = @cache.send(:read_entry, 'foo', {}).raw_value
|
@@ -297,30 +249,22 @@ module CacheStoreBehavior
|
|
297
249
|
|
298
250
|
def test_exist
|
299
251
|
@cache.write('foo', 'bar')
|
300
|
-
|
301
|
-
|
252
|
+
assert_equal true, @cache.exist?('foo')
|
253
|
+
assert_equal false, @cache.exist?('bar')
|
302
254
|
end
|
303
255
|
|
304
256
|
def test_nil_exist
|
305
257
|
@cache.write('foo', nil)
|
306
|
-
|
258
|
+
assert_equal true, @cache.exist?('foo')
|
307
259
|
end
|
308
260
|
|
309
261
|
def test_delete
|
310
262
|
@cache.write('foo', 'bar')
|
311
263
|
assert @cache.exist?('foo')
|
312
|
-
|
264
|
+
assert_equal true, @cache.delete('foo')
|
313
265
|
assert !@cache.exist?('foo')
|
314
266
|
end
|
315
267
|
|
316
|
-
def test_read_should_return_a_different_object_id_each_time_it_is_called
|
317
|
-
@cache.write('foo', 'bar')
|
318
|
-
assert_not_equal @cache.read('foo').object_id, @cache.read('foo').object_id
|
319
|
-
value = @cache.read('foo')
|
320
|
-
value << 'bingo'
|
321
|
-
assert_not_equal value, @cache.read('foo')
|
322
|
-
end
|
323
|
-
|
324
268
|
def test_original_store_objects_should_not_be_immutable
|
325
269
|
bar = 'bar'
|
326
270
|
@cache.write('foo', bar)
|
@@ -381,10 +325,10 @@ module CacheStoreBehavior
|
|
381
325
|
|
382
326
|
def test_crazy_key_characters
|
383
327
|
crazy_key = "#/:*(<+=> )&$%@?;'\"\'`~-"
|
384
|
-
|
328
|
+
assert_equal true, @cache.write(crazy_key, "1", :raw => true)
|
385
329
|
assert_equal "1", @cache.read(crazy_key)
|
386
330
|
assert_equal "1", @cache.fetch(crazy_key)
|
387
|
-
|
331
|
+
assert_equal true, @cache.delete(crazy_key)
|
388
332
|
assert_equal "2", @cache.fetch(crazy_key, :raw => true) { "2" }
|
389
333
|
assert_equal 3, @cache.increment(crazy_key)
|
390
334
|
assert_equal 2, @cache.decrement(crazy_key)
|
@@ -392,50 +336,13 @@ module CacheStoreBehavior
|
|
392
336
|
|
393
337
|
def test_really_long_keys
|
394
338
|
key = ""
|
395
|
-
|
396
|
-
|
339
|
+
1000.times{key << "x"}
|
340
|
+
assert_equal true, @cache.write(key, "bar")
|
397
341
|
assert_equal "bar", @cache.read(key)
|
398
342
|
assert_equal "bar", @cache.fetch(key)
|
399
343
|
assert_nil @cache.read("#{key}x")
|
400
344
|
assert_equal({key => "bar"}, @cache.read_multi(key))
|
401
|
-
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
# https://rails.lighthouseapp.com/projects/8994/tickets/6225-memcachestore-cant-deal-with-umlauts-and-special-characters
|
406
|
-
# The error is caused by charcter encodings that can't be compared with ASCII-8BIT regular expressions and by special
|
407
|
-
# characters like the umlaut in UTF-8.
|
408
|
-
module EncodedKeyCacheBehavior
|
409
|
-
if defined?(Encoding)
|
410
|
-
Encoding.list.each do |encoding|
|
411
|
-
define_method "test_#{encoding.name.underscore}_encoded_values" do
|
412
|
-
key = "foo".force_encoding(encoding)
|
413
|
-
assert @cache.write(key, "1", :raw => true)
|
414
|
-
assert_equal "1", @cache.read(key)
|
415
|
-
assert_equal "1", @cache.fetch(key)
|
416
|
-
assert @cache.delete(key)
|
417
|
-
assert_equal "2", @cache.fetch(key, :raw => true) { "2" }
|
418
|
-
assert_equal 3, @cache.increment(key)
|
419
|
-
assert_equal 2, @cache.decrement(key)
|
420
|
-
end
|
421
|
-
end
|
422
|
-
|
423
|
-
def test_common_utf8_values
|
424
|
-
key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8)
|
425
|
-
assert @cache.write(key, "1", :raw => true)
|
426
|
-
assert_equal "1", @cache.read(key)
|
427
|
-
assert_equal "1", @cache.fetch(key)
|
428
|
-
assert @cache.delete(key)
|
429
|
-
assert_equal "2", @cache.fetch(key, :raw => true) { "2" }
|
430
|
-
assert_equal 3, @cache.increment(key)
|
431
|
-
assert_equal 2, @cache.decrement(key)
|
432
|
-
end
|
433
|
-
|
434
|
-
def test_retains_encoding
|
435
|
-
key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8)
|
436
|
-
assert @cache.write(key, "1", :raw => true)
|
437
|
-
assert_equal Encoding::UTF_8, key.encoding
|
438
|
-
end
|
345
|
+
assert_equal true, @cache.delete(key)
|
439
346
|
end
|
440
347
|
end
|
441
348
|
|
@@ -446,10 +353,10 @@ module CacheDeleteMatchedBehavior
|
|
446
353
|
@cache.write("foo/bar", "baz")
|
447
354
|
@cache.write("fu/baz", "bar")
|
448
355
|
@cache.delete_matched(/oo/)
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
356
|
+
assert_equal false, @cache.exist?("foo")
|
357
|
+
assert_equal true, @cache.exist?("fu")
|
358
|
+
assert_equal false, @cache.exist?("foo/bar")
|
359
|
+
assert_equal true, @cache.exist?("fu/baz")
|
453
360
|
end
|
454
361
|
end
|
455
362
|
|
@@ -478,7 +385,7 @@ module LocalCacheBehavior
|
|
478
385
|
retval = @cache.with_local_cache do
|
479
386
|
@cache.write('foo', 'bar')
|
480
387
|
end
|
481
|
-
|
388
|
+
assert_equal true, retval
|
482
389
|
assert_equal 'bar', @cache.read('foo')
|
483
390
|
end
|
484
391
|
|
@@ -566,7 +473,6 @@ class FileStoreTest < ActiveSupport::TestCase
|
|
566
473
|
Dir.mkdir(cache_dir) unless File.exist?(cache_dir)
|
567
474
|
@cache = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, :expires_in => 60)
|
568
475
|
@peek = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, :expires_in => 60)
|
569
|
-
@cache_with_pathname = ActiveSupport::Cache.lookup_store(:file_store, Pathname.new(cache_dir), :expires_in => 60)
|
570
476
|
end
|
571
477
|
|
572
478
|
def teardown
|
@@ -586,83 +492,17 @@ class FileStoreTest < ActiveSupport::TestCase
|
|
586
492
|
key = @cache.send(:key_file_path, "views/index?id=1")
|
587
493
|
assert_equal "views/index?id=1", @cache.send(:file_path_key, key)
|
588
494
|
end
|
589
|
-
|
590
|
-
def test_key_transformation_with_pathname
|
591
|
-
FileUtils.touch(File.join(cache_dir, "foo"))
|
592
|
-
key = @cache_with_pathname.send(:key_file_path, "views/index?id=1")
|
593
|
-
assert_equal "views/index?id=1", @cache_with_pathname.send(:file_path_key, key)
|
594
|
-
end
|
595
|
-
|
596
|
-
# Because file systems have a maximum filename size, filenames > max size should be split in to directories
|
597
|
-
# If filename is 'AAAAB', where max size is 4, the returned path should be AAAA/B
|
598
|
-
def test_key_transformation_max_filename_size
|
599
|
-
key = "#{'A' * ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE}B"
|
600
|
-
path = @cache.send(:key_file_path, key)
|
601
|
-
assert path.split('/').all? { |dir_name| dir_name.size <= ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE}
|
602
|
-
assert_equal 'B', File.basename(path)
|
603
|
-
end
|
604
|
-
|
605
|
-
# If nothing has been stored in the cache, there is a chance the cache directory does not yet exist
|
606
|
-
# Ensure delete_matched gracefully handles this case
|
607
|
-
def test_delete_matched_when_cache_directory_does_not_exist
|
608
|
-
assert_nothing_raised(Exception) do
|
609
|
-
ActiveSupport::Cache::FileStore.new('/test/cache/directory').delete_matched(/does_not_exist/)
|
610
|
-
end
|
611
|
-
end
|
612
495
|
end
|
613
496
|
|
614
497
|
class MemoryStoreTest < ActiveSupport::TestCase
|
615
498
|
def setup
|
616
|
-
@
|
617
|
-
@cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60, :size => @record_size * 10)
|
499
|
+
@cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60, :size => 100)
|
618
500
|
end
|
619
501
|
|
620
502
|
include CacheStoreBehavior
|
621
503
|
include CacheDeleteMatchedBehavior
|
622
504
|
include CacheIncrementDecrementBehavior
|
623
505
|
|
624
|
-
def test_prune_size
|
625
|
-
@cache.write(1, "aaaaaaaaaa") && sleep(0.001)
|
626
|
-
@cache.write(2, "bbbbbbbbbb") && sleep(0.001)
|
627
|
-
@cache.write(3, "cccccccccc") && sleep(0.001)
|
628
|
-
@cache.write(4, "dddddddddd") && sleep(0.001)
|
629
|
-
@cache.write(5, "eeeeeeeeee") && sleep(0.001)
|
630
|
-
@cache.read(2) && sleep(0.001)
|
631
|
-
@cache.read(4)
|
632
|
-
@cache.prune(@record_size * 3)
|
633
|
-
assert @cache.exist?(5)
|
634
|
-
assert @cache.exist?(4)
|
635
|
-
assert !@cache.exist?(3)
|
636
|
-
assert @cache.exist?(2)
|
637
|
-
assert !@cache.exist?(1)
|
638
|
-
end
|
639
|
-
|
640
|
-
def test_prune_size_on_write
|
641
|
-
@cache.write(1, "aaaaaaaaaa") && sleep(0.001)
|
642
|
-
@cache.write(2, "bbbbbbbbbb") && sleep(0.001)
|
643
|
-
@cache.write(3, "cccccccccc") && sleep(0.001)
|
644
|
-
@cache.write(4, "dddddddddd") && sleep(0.001)
|
645
|
-
@cache.write(5, "eeeeeeeeee") && sleep(0.001)
|
646
|
-
@cache.write(6, "ffffffffff") && sleep(0.001)
|
647
|
-
@cache.write(7, "gggggggggg") && sleep(0.001)
|
648
|
-
@cache.write(8, "hhhhhhhhhh") && sleep(0.001)
|
649
|
-
@cache.write(9, "iiiiiiiiii") && sleep(0.001)
|
650
|
-
@cache.write(10, "kkkkkkkkkk") && sleep(0.001)
|
651
|
-
@cache.read(2) && sleep(0.001)
|
652
|
-
@cache.read(4) && sleep(0.001)
|
653
|
-
@cache.write(11, "llllllllll")
|
654
|
-
assert @cache.exist?(11)
|
655
|
-
assert @cache.exist?(10)
|
656
|
-
assert @cache.exist?(9)
|
657
|
-
assert @cache.exist?(8)
|
658
|
-
assert @cache.exist?(7)
|
659
|
-
assert !@cache.exist?(6)
|
660
|
-
assert !@cache.exist?(5)
|
661
|
-
assert @cache.exist?(4)
|
662
|
-
assert !@cache.exist?(3)
|
663
|
-
assert @cache.exist?(2)
|
664
|
-
assert !@cache.exist?(1)
|
665
|
-
end
|
666
506
|
|
667
507
|
def test_pruning_is_capped_at_a_max_time
|
668
508
|
def @cache.delete_entry (*args)
|
@@ -675,14 +515,26 @@ class MemoryStoreTest < ActiveSupport::TestCase
|
|
675
515
|
@cache.write(4, "dddddddddd") && sleep(0.001)
|
676
516
|
@cache.write(5, "eeeeeeeeee") && sleep(0.001)
|
677
517
|
@cache.prune(30, 0.001)
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
518
|
+
assert_equal true, @cache.exist?(5)
|
519
|
+
assert_equal true, @cache.exist?(4)
|
520
|
+
assert_equal true, @cache.exist?(3)
|
521
|
+
assert_equal true, @cache.exist?(2)
|
522
|
+
assert_equal false, @cache.exist?(1)
|
683
523
|
end
|
684
524
|
end
|
685
525
|
|
526
|
+
class SynchronizedStoreTest < ActiveSupport::TestCase
|
527
|
+
def setup
|
528
|
+
ActiveSupport::Deprecation.silence do
|
529
|
+
@cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60)
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
include CacheStoreBehavior
|
534
|
+
include CacheDeleteMatchedBehavior
|
535
|
+
include CacheIncrementDecrementBehavior
|
536
|
+
end
|
537
|
+
|
686
538
|
uses_memcached 'memcached backed store' do
|
687
539
|
class MemCacheStoreTest < ActiveSupport::TestCase
|
688
540
|
def setup
|
@@ -697,7 +549,6 @@ uses_memcached 'memcached backed store' do
|
|
697
549
|
include CacheStoreBehavior
|
698
550
|
include LocalCacheBehavior
|
699
551
|
include CacheIncrementDecrementBehavior
|
700
|
-
include EncodedKeyCacheBehavior
|
701
552
|
|
702
553
|
def test_raw_values
|
703
554
|
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
|
@@ -706,13 +557,6 @@ uses_memcached 'memcached backed store' do
|
|
706
557
|
assert_equal "2", cache.read("foo")
|
707
558
|
end
|
708
559
|
|
709
|
-
def test_raw_values_with_marshal
|
710
|
-
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
|
711
|
-
cache.clear
|
712
|
-
cache.write("foo", Marshal.dump([]))
|
713
|
-
assert_equal [], cache.read("foo")
|
714
|
-
end
|
715
|
-
|
716
560
|
def test_local_cache_raw_values
|
717
561
|
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
|
718
562
|
cache.clear
|
@@ -721,73 +565,6 @@ uses_memcached 'memcached backed store' do
|
|
721
565
|
assert_equal "2", cache.read("foo")
|
722
566
|
end
|
723
567
|
end
|
724
|
-
|
725
|
-
def test_local_cache_raw_values_with_marshal
|
726
|
-
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
|
727
|
-
cache.clear
|
728
|
-
cache.with_local_cache do
|
729
|
-
cache.write("foo", Marshal.dump([]))
|
730
|
-
assert_equal [], cache.read("foo")
|
731
|
-
end
|
732
|
-
end
|
733
|
-
end
|
734
|
-
end
|
735
|
-
|
736
|
-
class NullStoreTest < ActiveSupport::TestCase
|
737
|
-
def setup
|
738
|
-
@cache = ActiveSupport::Cache.lookup_store(:null_store)
|
739
|
-
end
|
740
|
-
|
741
|
-
def test_clear
|
742
|
-
@cache.clear
|
743
|
-
end
|
744
|
-
|
745
|
-
def test_cleanup
|
746
|
-
@cache.cleanup
|
747
|
-
end
|
748
|
-
|
749
|
-
def test_write
|
750
|
-
assert_equal true, @cache.write("name", "value")
|
751
|
-
end
|
752
|
-
|
753
|
-
def test_read
|
754
|
-
@cache.write("name", "value")
|
755
|
-
assert_nil @cache.read("name")
|
756
|
-
end
|
757
|
-
|
758
|
-
def test_delete
|
759
|
-
@cache.write("name", "value")
|
760
|
-
assert_equal false, @cache.delete("name")
|
761
|
-
end
|
762
|
-
|
763
|
-
def test_increment
|
764
|
-
@cache.write("name", 1, :raw => true)
|
765
|
-
assert_nil @cache.increment("name")
|
766
|
-
end
|
767
|
-
|
768
|
-
def test_decrement
|
769
|
-
@cache.write("name", 1, :raw => true)
|
770
|
-
assert_nil @cache.increment("name")
|
771
|
-
end
|
772
|
-
|
773
|
-
def test_delete_matched
|
774
|
-
@cache.write("name", "value")
|
775
|
-
@cache.delete_matched(/name/)
|
776
|
-
end
|
777
|
-
|
778
|
-
def test_local_store_strategy
|
779
|
-
@cache.with_local_cache do
|
780
|
-
@cache.write("name", "value")
|
781
|
-
assert_equal "value", @cache.read("name")
|
782
|
-
@cache.delete("name")
|
783
|
-
assert_nil @cache.read("name")
|
784
|
-
@cache.write("name", "value")
|
785
|
-
end
|
786
|
-
assert_nil @cache.read("name")
|
787
|
-
end
|
788
|
-
|
789
|
-
def test_setting_nil_cache_store
|
790
|
-
assert ActiveSupport::Cache.lookup_store.class.name, ActiveSupport::Cache::NullStore.name
|
791
568
|
end
|
792
569
|
end
|
793
570
|
|
@@ -816,31 +593,24 @@ class CacheEntryTest < ActiveSupport::TestCase
|
|
816
593
|
entry = ActiveSupport::Cache::Entry.create("raw", time, :compress => false, :expires_in => 300)
|
817
594
|
assert_equal "raw", entry.raw_value
|
818
595
|
assert_equal time.to_f, entry.created_at
|
819
|
-
|
596
|
+
assert_nil entry.compressed?.presence
|
820
597
|
assert_equal 300, entry.expires_in
|
821
598
|
end
|
822
599
|
|
823
600
|
def test_expired
|
824
601
|
entry = ActiveSupport::Cache::Entry.new("value")
|
825
|
-
|
602
|
+
assert_nil entry.expired?.presence
|
826
603
|
entry = ActiveSupport::Cache::Entry.new("value", :expires_in => 60)
|
827
|
-
|
604
|
+
assert_nil entry.expired?.presence
|
828
605
|
time = Time.now + 61
|
829
606
|
Time.stubs(:now).returns(time)
|
830
|
-
|
607
|
+
assert_equal true, entry.expired?
|
831
608
|
end
|
832
609
|
|
833
610
|
def test_compress_values
|
834
611
|
entry = ActiveSupport::Cache::Entry.new("value", :compress => true, :compress_threshold => 1)
|
835
612
|
assert_equal "value", entry.value
|
836
|
-
|
613
|
+
assert_equal true, entry.compressed?
|
837
614
|
assert_equal "value", Marshal.load(Zlib::Inflate.inflate(entry.raw_value))
|
838
615
|
end
|
839
|
-
|
840
|
-
def test_non_compress_values
|
841
|
-
entry = ActiveSupport::Cache::Entry.new("value")
|
842
|
-
assert_equal "value", entry.value
|
843
|
-
assert_equal "value", Marshal.load(entry.raw_value)
|
844
|
-
assert !entry.compressed?
|
845
|
-
end
|
846
|
-
end
|
616
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-cache-tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-09 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: rails
|
16
|
+
requirement: &20365460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *20365460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement: &
|
26
|
+
name: appraisal
|
27
|
+
requirement: &20364680 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
33
|
-
type: :
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *20364680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: minitest
|
38
|
-
requirement: &
|
38
|
+
requirement: &20363940 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3.2'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *20363940
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: memcache-client
|
49
|
-
requirement: &
|
49
|
+
requirement: &20363440 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *20363440
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rack
|
60
|
-
requirement: &
|
60
|
+
requirement: &20362660 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *20362660
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mocha
|
71
|
-
requirement: &
|
71
|
+
requirement: &20361940 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *20361940
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: simplecov
|
82
|
-
requirement: &
|
82
|
+
requirement: &20361520 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *20361520
|
91
91
|
description: Tagged caching support for Rails
|
92
92
|
email:
|
93
93
|
- amikhailov83@gmail.com
|
@@ -96,6 +96,7 @@ extensions: []
|
|
96
96
|
extra_rdoc_files: []
|
97
97
|
files:
|
98
98
|
- .gitignore
|
99
|
+
- Appraisals
|
99
100
|
- Gemfile
|
100
101
|
- LICENSE
|
101
102
|
- README.md
|
@@ -120,12 +121,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
121
|
- - ! '>='
|
121
122
|
- !ruby/object:Gem::Version
|
122
123
|
version: '0'
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
hash: -1686496298142022939
|
123
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
128
|
none: false
|
125
129
|
requirements:
|
126
130
|
- - ! '>='
|
127
131
|
- !ruby/object:Gem::Version
|
128
132
|
version: '0'
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
hash: -1686496298142022939
|
129
136
|
requirements: []
|
130
137
|
rubyforge_project:
|
131
138
|
rubygems_version: 1.8.17
|