aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorJeremy Daer <jeremydaer@gmail.com>2017-11-13 19:16:53 -0700
committerJeremy Daer <jeremydaer@gmail.com>2017-11-13 22:02:45 -0700
commited100166874fb4a542c5aaba933a4cca5ed72269 (patch)
tree2ff1d0fc88cbf9e10dc85c873765b4e6d06fa7e8 /activesupport/test
parentb6d5e46311d7ea59539c1f45c6ffb269eeb23912 (diff)
downloadrails-ed100166874fb4a542c5aaba933a4cca5ed72269.tar.gz
rails-ed100166874fb4a542c5aaba933a4cca5ed72269.tar.bz2
rails-ed100166874fb4a542c5aaba933a4cca5ed72269.zip
Cache: Enable compression by default for values > 1kB.
Compression has long been available, but opt-in and at a 16kB threshold. It wasn't enabled by default due to CPU cost. Today it's cheap and typical cache data is eminently compressible, such as HTML or JSON fragments. Compression dramatically reduces Memcached/Redis mem usage, which means the same cache servers can store more data, which means higher hit rates. To disable compression, pass `compress: false` to the initializer.
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/cache/behaviors/cache_store_behavior.rb10
-rw-r--r--activesupport/test/cache/cache_entry_test.rb13
2 files changed, 20 insertions, 3 deletions
diff --git a/activesupport/test/cache/behaviors/cache_store_behavior.rb b/activesupport/test/cache/behaviors/cache_store_behavior.rb
index 582e902f72..73a9b2a71c 100644
--- a/activesupport/test/cache/behaviors/cache_store_behavior.rb
+++ b/activesupport/test/cache/behaviors/cache_store_behavior.rb
@@ -146,6 +146,16 @@ module CacheStoreBehavior
assert_nil @cache.read("foo")
end
+ def test_read_and_write_uncompressed_small_data
+ @cache.write("foo", "bar", compress: false)
+ assert_equal "bar", @cache.read("foo")
+ end
+
+ def test_read_and_write_uncompressed_nil
+ @cache.write("foo", nil, compress: false)
+ assert_nil @cache.read("foo")
+ end
+
def test_cache_key
obj = Object.new
def obj.cache_key
diff --git a/activesupport/test/cache/cache_entry_test.rb b/activesupport/test/cache/cache_entry_test.rb
index 51b214ad8f..80ff7ad564 100644
--- a/activesupport/test/cache/cache_entry_test.rb
+++ b/activesupport/test/cache/cache_entry_test.rb
@@ -14,16 +14,23 @@ class CacheEntryTest < ActiveSupport::TestCase
end
end
- def test_compress_values
+ def test_compressed_values
value = "value" * 100
entry = ActiveSupport::Cache::Entry.new(value, compress: true, compress_threshold: 1)
assert_equal value, entry.value
assert(value.bytesize > entry.size, "value is compressed")
end
- def test_non_compress_values
+ def test_compressed_by_default
value = "value" * 100
- entry = ActiveSupport::Cache::Entry.new(value)
+ entry = ActiveSupport::Cache::Entry.new(value, compress_threshold: 1)
+ assert_equal value, entry.value
+ assert(value.bytesize > entry.size, "value is compressed")
+ end
+
+ def test_uncompressed_values
+ value = "value" * 100
+ entry = ActiveSupport::Cache::Entry.new(value, compress: false)
assert_equal value, entry.value
assert_equal value.bytesize, entry.size
end