rails-brotli-cache 0.3.3 → 0.3.5

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: 93b71dde73a988ed1a008810be38e9b30311896e41cf3c6017feebbfce4fec32
4
- data.tar.gz: c3c9b8da01d4e3bcadd33fca01a3648b591db18dc807536190f43f34a4af2159
3
+ metadata.gz: 0d2a98f625745f1051b66f22f71dfb7c284eec5d8a1087378222bea371543803
4
+ data.tar.gz: dbd97601e6ca601ffe088bbeeb2491e00fd8f34c9f363cf263228630f8cdfcc9
5
5
  SHA512:
6
- metadata.gz: 33648f7e5a975d4c87ea10356e2ea5dc5220ade8d6a188ba3891a5387b47506079d4f4c7763f61458663868835e16f721489cd16132cd6ca671807531f14f0cc
7
- data.tar.gz: 27d9f9b5c42134eccd351807bfd44f4d6fcc19baae2ef13a466f013c95406971feab785bced3c82827a709342f4a0672b7dee0e012f2f7c2003fac267daf7d43
6
+ metadata.gz: d58c6cdd1fc0c569e7ed2d2c76584a91fcef49be8aaacfa80875b32a7995590fa441a9dfa0fd8a0dbdf554cbe95b5c2bd424358146c311a9d98a11fd3b0a3ad9
7
+ data.tar.gz: 308a8e81bd0ed6909b2dd5184a27bdcfcdbad3708e259af0f5a6c13902afb5b98f721341ad8a016d2a9935d6baf0fcb2ff9d14059aef6b5cca44c42487184884
data/README.md CHANGED
@@ -1,10 +1,12 @@
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 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
+
5
+ I'm currently working on a post describing the gem in more detail. You can subscribe to [my blog's mailing list](https://eepurl.com/dhuFg5) or [follow me on Twitter](https://twitter.com/_pawurb) to get notified when it's out.
4
6
 
5
7
  ## Benchmarks
6
8
 
7
- Brotli cache works as a proxy layer wrapping the underlying cache data store.
9
+ 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
10
 
9
11
  ```ruby
10
12
  redis_cache = ActiveSupport::Cache::RedisCacheStore.new(
@@ -23,8 +25,8 @@ brotli_redis_cache.write("json", json)
23
25
 
24
26
  ## Check the size of cache entries stored in Redis
25
27
  redis = Redis.new(url: "redis://localhost:6379")
26
- redis.get("json").size # => 31698
27
- redis.get("br-json").size # => 24058
28
+ redis.get("json").size # => 31698 ~31kb
29
+ redis.get("br-json").size # => 24058 ~24kb
28
30
  ```
29
31
 
30
32
  **~20%** better compression of a sample ActiveRecord objects array:
@@ -34,8 +36,8 @@ users = User.limit(100).to_a # 100 ActiveRecord objects
34
36
  redis_cache.write("users", users)
35
37
  brotli_redis_cache.write("users", users)
36
38
 
37
- redis.get("users").size # => 12331
38
- redis.get("br-users").size # => 10299
39
+ redis.get("users").size # => 12331 ~12kb
40
+ redis.get("br-users").size # => 10299 ~10kb
39
41
  ```
40
42
 
41
43
  **~25%** faster performance for reading/writing a larger JSON file:
@@ -72,6 +72,8 @@ module RailsBrotliCache
72
72
 
73
73
  return nil unless payload.present?
74
74
 
75
+ return payload if payload.is_a?(Integer)
76
+
75
77
  serialized = if payload.start_with?(MARK_BR_COMPRESSED)
76
78
  compressor = compressor_class(options, default: @compressor_class)
77
79
  compressor.inflate(payload.byteslice(1..-1))
@@ -94,6 +96,18 @@ module RailsBrotliCache
94
96
  @core_store.clear
95
97
  end
96
98
 
99
+ def increment(name, amount = 1, options = nil)
100
+ @core_store.increment(cache_key(name), amount, options)
101
+ end
102
+
103
+ def decrement(name, amount = 1, options = nil)
104
+ @core_store.decrement(cache_key(name), amount, options)
105
+ end
106
+
107
+ def self.supports_cache_versioning?
108
+ true
109
+ end
110
+
97
111
  private
98
112
 
99
113
  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.3"
4
+ VERSION = "0.3.5"
5
5
  end
@@ -40,6 +40,20 @@ describe RailsBrotliCache do
40
40
  end
41
41
  end
42
42
 
43
+ describe "#increment and #decrement" do
44
+ it "works" do
45
+ cache_store.write("integer-key", 0)
46
+ cache_store.increment("integer-key")
47
+ expect(cache_store.read("integer-key")).to eq 1
48
+ cache_store.increment("integer-key", 3)
49
+ expect(cache_store.read("integer-key")).to eq 4
50
+ cache_store.decrement("integer-key", 4)
51
+ expect(cache_store.read("integer-key")).to eq 0
52
+ cache_store.decrement("integer-key")
53
+ expect(cache_store.read("integer-key")).to eq -1
54
+ end
55
+ end
56
+
43
57
  describe "exist?" do
44
58
  it "returns true if cache entry exists" do
45
59
  cache_store.write("test-key", 1234)
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.3
4
+ version: 0.3.5
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-22 00:00:00.000000000 Z
11
+ date: 2023-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails