cached_resource icon indicating copy to clipboard operation
cached_resource copied to clipboard

Redis cache does not support ^ in the delete_matched definition

Open Wardormeur opened this issue 1 year ago • 4 comments

When running a clear_cache, the ^ does not seem to supported In Redis cache store, the pattern used is sent to scan https://github.com/rails/rails/blob/main/activesupport/lib/active_support/cache/redis_cache_store.rb#L198 Trying to rerun it as close as possible to redis, we notice the ^ blocks retrieval of keys

Example:

 r.scan(0, :match => "deal/*", count: 100)
=> 
["476",
 ["deal/product/all/{:params=>{:universe_id=>2,:q=>{:published_eq=>true}}}",
  "deal/category/5/relevant-products-for-newborn",
  "deal/brand/25",
  "deal/product/all/{:params=>{:category_id=>6,:q=>{:published_eq=>true}}}",
  "deal/product/all/{:params=>{:category_id=>11,:q=>{:published_eq=>true}}}",
  "deal/universe/all",
  "deal/product/all/{:params=>{:category_id=>4,:q=>{:published_eq=>true}}}",
  "deal/category/11/relevant-products-for-newborn",
  "deal/brand/8",
  "deal/product/all/{:params=>{:category_id=>15,:q=>{:published_eq=>true}}}",
  "deal/brand/all/{:params=>{:q=>{:published_eq=>true,:random=>true}}}",
  "deal/product/all/{:params=>{:category_id=>9,:q=>{:published_eq=>true}}}",
  "deal/brand/21",
  "deal/brand/4",
  "deal/brand/13",
  "deal/brand/16",
  "deal/brand/12"]]
> r.scan(0, :match => "^deal/*", count: 100)
=> ["476", []]

Wardormeur avatar May 29 '24 13:05 Wardormeur

Ah so then https://github.com/mhgbrown/cached_resource/blob/a2d1b33e260be60e12d7a3bbb662d62e102065b5/lib/cached_resource/caching.rb#L151 does not work.

So for Redis, we should omit the ^? Does that sound right?

mhgbrown avatar May 31 '24 14:05 mhgbrown

Yup, that sounds about right

Wardormeur avatar Jul 04 '24 12:07 Wardormeur

Will patch this :)

jlurena avatar Jul 05 '24 15:07 jlurena

Done https://github.com/mhgbrown/cached_resource/pull/67

jlurena avatar Jul 05 '24 18:07 jlurena