solid_cache 0.1.0 → 0.2.0

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: '0649423e526a66fa9554f73d215e7e49c6ff093c004c1641d72a670a33688468'
4
- data.tar.gz: ad56d9f53b6b0c6f9dcc049771a187e95c5e2cceeabeaa07286f96212f5b0fb7
3
+ metadata.gz: 98f4ca743bf44353244b4e1bb870df48b426fcb8b082941ad0f07e150f05cffb
4
+ data.tar.gz: 85a3660e7c8b63b8f838039228b887f6a4ecde5d17401707f243804efb7f98d6
5
5
  SHA512:
6
- metadata.gz: 900011771476bff6c3b3ec5abe087a0dcf00596f6e200dec961aa7e13f3ad4d978d9ac8858d3912b8bc0bc63a8742de4e925bd04b120d15badb890448946f4c2
7
- data.tar.gz: c9fd66e658ec1e38f628c592053f330179571a7299a1d4e6bae88a959996c10c4d7df158c30c9827464e0c3af526a4b5c0100f55f51c5b3e563e73b5af93226a
6
+ metadata.gz: 2251bc348573da1c8492f299cd7fadbd87450ad22252ae388b25c842b71bf6cf6525d40243587d3c2951c8af1a71fb0ac42af6eedde767465ab08a7cfcfbe9b6
7
+ data.tar.gz: 1e69812734160e29b7ae9430303243f23f09f24a75440da61e7dd5d0efd0ac6e4934e0d7a6566791c60f3cf1d88e8d45364f9904bd60b742f16aa8241e0c1fbb
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Solid Cache
2
2
 
3
- Solid Cache is a database-backed Active Support cache store implementation.
3
+ Solid Cache is a database-backed Active Support cache store implementation.
4
4
 
5
5
  Using SQL databases backed by SSDs we can have caches that are much larger and cheaper than traditional memory only Redis or Memcached backed caches.
6
6
 
@@ -58,7 +58,7 @@ $ bin/rails db:migrate
58
58
  There are two options that can be set on the engine:
59
59
 
60
60
  - `executor` - the [Rails executor](https://guides.rubyonrails.org/threading_and_code_execution.html#executor) used to wrap asynchronous operations, defaults to the app executor
61
- - `connects_to` - a custom connects to value for the abstract `SolidCache::Record` active record model. Requires for sharding and/or using a separate cache database to the main app.
61
+ - `connects_to` - a custom connects to value for the abstract `SolidCache::Record` active record model. Required for sharding and/or using a separate cache database to the main app.
62
62
 
63
63
  These can be set in your Rails configuration:
64
64
 
@@ -81,7 +81,7 @@ Solid Cache supports these options in addition to the standard `ActiveSupport::C
81
81
  - `expiry_batch_size` - the batch size to use when deleting old records (default: `100`)
82
82
  - `expiry_method` - what expiry method to use `thread` or `job` (default: `thread`)
83
83
  - `max_age` - the maximum age of entries in the cache (default: `2.weeks.to_i`)
84
- - `max_entries` - the maximum number of entries allowed in the cache (default: `2.weeks.to_i`)
84
+ - `max_entries` - the maximum number of entries allowed in the cache (default: `nil`, meaning no limit)
85
85
  - `cluster` - a Hash of options for the cache database cluster, e.g `{ shards: [:database1, :database2, :database3] }`
86
86
  - `clusters` - and Array of Hashes for multiple cache clusters (ignored if `:cluster` is set)
87
87
  - `active_record_instrumentation` - whether to instrument the cache's queries (default: `true`)
@@ -92,7 +92,7 @@ For more information on cache clusters see [Sharding the cache](#sharding-the-ca
92
92
 
93
93
  ### Cache expiry
94
94
 
95
- Solid Cache tracks writes to the cache. For every write it increments a counter by 1. Once the counter reaches 80% of the `expiry_batch_size` it add a task to run on a background thread. That task will:
95
+ Solid Cache tracks writes to the cache. For every write it increments a counter by 1. Once the counter reaches 80% of the `expiry_batch_size` it adds a task to run on a background thread. That task will:
96
96
 
97
97
  1. Check if we have exceeded the `max_entries` value (if set) by subtracting the max and min IDs from the `SolidCache::Entry` table (this is an estimate that ignores any gaps).
98
98
  2. If we have it will delete `expiry_batch_size` entries
@@ -109,7 +109,7 @@ If you want the cache expiry to be run in a background job instead of a thread,
109
109
  Add database configuration to database.yml, e.g.:
110
110
 
111
111
  ```
112
- development
112
+ development:
113
113
  cache:
114
114
  database: cache_development
115
115
  host: 127.0.0.1
@@ -135,7 +135,7 @@ $ mv db/migrate/*.solid_cache.rb db/cache/migrate
135
135
  Set the engine configuration to point to the new database:
136
136
  ```
137
137
  Rails.application.configure do
138
- config.solid_cache.connects_to = { default: { writing: :cache } }
138
+ config.solid_cache.connects_to = { database: { writing: :cache } }
139
139
  end
140
140
  ```
141
141
 
@@ -250,19 +250,48 @@ The Solid Cache migrations try to create an index with 1024 byte entries. If tha
250
250
 
251
251
  ## Development
252
252
 
253
- Run the tests with `bin/rails test`. These will run against SQLite.
253
+ Run the tests with `bin/rails test`. By default, these will run against SQLite.
254
254
 
255
- You can also run the tests against MySQL and Postgres. First start up the databases:
255
+ You can also run the tests against MySQL and PostgreSQL. First start up the databases:
256
256
 
257
257
  ```shell
258
258
  $ docker compose up -d
259
259
  ```
260
260
 
261
- Then run the tests for the target database
261
+ Next, setup the database schema:
262
+
263
+ ```shell
264
+ $ TARGET_DB=mysql bin/rails db:setup
265
+ $ TARGET_DB=postgres bin/rails db:setup
262
266
  ```
267
+
268
+
269
+ Then run the tests for the target database:
270
+
271
+ ```shell
263
272
  $ TARGET_DB=mysql bin/rails test
264
273
  $ TARGET_DB=postgres bin/rails test
265
274
  ```
266
275
 
276
+ ### Testing with multiple Rails version
277
+
278
+ Solid Cache relies on [appraisal](https://github.com/thoughtbot/appraisal/tree/main) to test
279
+ multiple Rails version.
280
+
281
+ To run a test for a specific version run:
282
+
283
+ ```shell
284
+ bundle exec appraisal rails-7-1 bin/rails test
285
+ ```
286
+
287
+ After updating the dependencies in then `Gemfile` please run:
288
+
289
+ ```shell
290
+ $ bundle
291
+ $ appraisal update
292
+ ```
293
+
294
+ This ensures that all the Rails versions dependencies are updated.
295
+
267
296
  ## License
268
297
  Solid Cache is licensed under MIT.
@@ -21,10 +21,6 @@ module SolidCache
21
21
  select_all_no_query_cache(get_all_sql(serialized_keys), serialized_keys).to_h
22
22
  end
23
23
 
24
- def expire(ids)
25
- delete_no_query_cache(:id, ids) if ids.any?
26
- end
27
-
28
24
  def delete_by_key(key)
29
25
  delete_no_query_cache(:key, to_binary(key))
30
26
  end
@@ -78,8 +74,12 @@ module SolidCache
78
74
  message = +"#{self} "
79
75
  message << "Bulk " if attributes.many?
80
76
  message << "Upsert"
81
- # exec_query does not clear the query cache, exec_insert_all does
82
- connection.exec_query sql, message
77
+ # exec_query_method does not clear the query cache, exec_insert_all does
78
+ connection.send exec_query_method, sql, message
79
+ end
80
+
81
+ def exec_query_method
82
+ connection.respond_to?(:internal_exec_query) ? :internal_exec_query : :exec_query
83
83
  end
84
84
 
85
85
  def upsert_unique_by
@@ -4,7 +4,7 @@ module SolidCache
4
4
  class MaglevHash
5
5
  attr_reader :nodes
6
6
 
7
- #  Must be prime
7
+ # Must be prime
8
8
  TABLE_SIZE = 2053
9
9
 
10
10
  def initialize(nodes)
@@ -88,7 +88,14 @@ module SolidCache
88
88
  if entry.expired?
89
89
  delete_entry(key, **options)
90
90
  elsif !entry.mismatched?(version)
91
- results[name] = entry.value
91
+ if defined? ActiveSupport::Cache::DeserializationError
92
+ begin
93
+ results[name] = entry.value
94
+ rescue ActiveSupport::Cache::DeserializationError
95
+ end
96
+ else
97
+ results[name] = entry.value
98
+ end
92
99
  end
93
100
  end
94
101
  end
@@ -1,3 +1,3 @@
1
1
  module SolidCache
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donal McBreen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-02 00:00:00.000000000 Z
11
+ date: 2023-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.4.17
112
+ rubygems_version: 3.4.21
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: A database backed ActiveSupport::Cache::Store