rails-brotli-cache 0.3.2 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c53c91a3df8a561eadcb309bc1a0a3315ca331ec36fe9bfe0995b21dc09c821b
4
- data.tar.gz: d74f60c63d75643f57ac1c3568b436ed817dcb69e73cd19d4ab369c420deeba2
3
+ metadata.gz: 412dc55dcd3f00210f9c090472b3dfcf10bedba7c2882015a74349797bfe4197
4
+ data.tar.gz: 7f8085d5fc354f899db174cf6080ea5f03a06f97a714afbb56b9f05aee801a2e
5
5
  SHA512:
6
- metadata.gz: f2f4b9f01712a860dd57b6da48cb284c68a92593a50955796abf8eafd8b32e5b712233d0e7029aa3c26ed65b098547e25a3311b83cf6c94f8c6f74b2cdcaf443
7
- data.tar.gz: c858ee0fd911aa7805ed2b74ab9dc15328b3584918b5da262b60df3a8a27f9982412b00001ba9da4f189038c57e9b0e2620116dba60b4982b91b5da8f7ad8ae4
6
+ metadata.gz: 539de77bdcf9cd35b99023859a8e9c8d4cb25c99161ea32699a11818ec45f38165bf29bc7a738fb57e6ee39c8774460b9e2b8a626e77cbf1ed597b3178e6e0c4
7
+ data.tar.gz: 18326136e7fe619a5af79e6bb3ea803a0656a06aacdf624c7c5f8fd2ef7d175a1a9b24583675b96155e5dd3fc8e838b2dee4bdb3100366c6a799e7462c216c9d
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Rails Brotli Cache [![Gem Version](https://img.shields.io/gem/v/rails-brotli-cache)](https://badge.fury.io/rb/rails-brotli-cache) [![CircleCI](https://circleci.com/gh/pawurb/rails-brotli-cache.svg?style=svg)](https://circleci.com/gh/pawurb/rails-brotli-cache)
2
2
 
3
- This gem enables support for compressing Ruby on Rails cache entries using the [Brotli compression algorithm](https://github.com/google/brotli). `RailsBrotliCache::Store` offers better compression and faster performance compared to the default `Rails.cache`, regardless of the underlying data store. The gem also allows specifying any custom compression algorithm instead of Brotli.
3
+ This gem enables support for compressing Ruby on Rails cache entries using the [Brotli compression algorithm](https://github.com/google/brotli). `RailsBrotliCache::Store` offers better compression and performance compared to the default `Rails.cache` Gzip, regardless of the underlying data store. The gem also allows specifying any custom compression algorithm instead of Brotli.
4
4
 
5
5
  ## Benchmarks
6
6
 
7
- Brotli cache works as a proxy layer wrapping the underlying cache data store.
7
+ Brotli cache works as a proxy layer wrapping the standard cache data store. It applies Brotli compression instead of the default Gzip before storing cache entries.
8
8
 
9
9
  ```ruby
10
10
  redis_cache = ActiveSupport::Cache::RedisCacheStore.new(
@@ -23,8 +23,8 @@ brotli_redis_cache.write("json", json)
23
23
 
24
24
  ## Check the size of cache entries stored in Redis
25
25
  redis = Redis.new(url: "redis://localhost:6379")
26
- redis.get("json").size # => 31698
27
- redis.get("br-json").size # => 24058
26
+ redis.get("json").size # => 31698 ~31kb
27
+ redis.get("br-json").size # => 24058 ~24kb
28
28
  ```
29
29
 
30
30
  **~20%** better compression of a sample ActiveRecord objects array:
@@ -34,8 +34,8 @@ users = User.limit(100).to_a # 100 ActiveRecord objects
34
34
  redis_cache.write("users", users)
35
35
  brotli_redis_cache.write("users", users)
36
36
 
37
- redis.get("users").size # => 12331
38
- redis.get("br-users").size # => 10299
37
+ redis.get("users").size # => 12331 ~12kb
38
+ redis.get("br-users").size # => 10299 ~10kb
39
39
  ```
40
40
 
41
41
  **~25%** faster performance for reading/writing a larger JSON file:
@@ -103,7 +103,7 @@ config.cache_store = RailsBrotliCache::Store.new(
103
103
  )
104
104
  ```
105
105
 
106
- You should avoid using it with `ActiveSupport::Cache::MemoryStore`. This type of cache store does not serialize or compress objects but keeps them directly in the RAM of a Ruby process. In this case, adding this gem would reduce RAM usage but add huge performance overhead.
106
+ You should avoid using it with `ActiveSupport::Cache::MemoryStore`. This type of cache store does not serialize or compress objects but keeps them directly in the RAM. In this case, adding this gem would reduce RAM usage but add huge performance overhead.
107
107
 
108
108
  Gem appends `br-` to the cache key names to prevent conflicts with previously saved entries. You can disable this behavior by passing `{ prefix: nil }` during initialization:
109
109
 
@@ -82,6 +82,10 @@ module RailsBrotliCache
82
82
  Marshal.load(serialized)
83
83
  end
84
84
 
85
+ def exist?(name, options = nil)
86
+ @core_store.exist?(cache_key(name), options)
87
+ end
88
+
85
89
  def delete(name, options = nil)
86
90
  @core_store.delete(cache_key(name), options)
87
91
  end
@@ -90,6 +94,10 @@ module RailsBrotliCache
90
94
  @core_store.clear
91
95
  end
92
96
 
97
+ def self.supports_cache_versioning?
98
+ true
99
+ end
100
+
93
101
  private
94
102
 
95
103
  def compressor_class(options, default:)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBrotliCache
4
- VERSION = "0.3.2"
4
+ VERSION = "0.3.4"
5
5
  end
@@ -40,6 +40,17 @@ describe RailsBrotliCache do
40
40
  end
41
41
  end
42
42
 
43
+ describe "exist?" do
44
+ it "returns true if cache entry exists" do
45
+ cache_store.write("test-key", 1234)
46
+ expect(cache_store.exist?("test-key")).to eq true
47
+ end
48
+
49
+ it "returns false if cache entry does not exist" do
50
+ expect(cache_store.exist?("test-key")).to eq false
51
+ end
52
+ end
53
+
43
54
  describe "#core_store" do
44
55
  it "exposes the underlying data store" do
45
56
  expect(cache_store.core_store.class).to eq ActiveSupport::Cache::MemoryStore
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-brotli-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-21 00:00:00.000000000 Z
11
+ date: 2023-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails