You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously all classes shared a single global Cacheable.cache_adapter.
Now each class that includes Cacheable can set its own adapter via
MyClass.cache_adapter=, falling back to the global adapter when
not configured.
Changes:
- Extend including classes with CacheAdapter
- CacheAdapter#cache_adapter falls back to Cacheable.cache_adapter
when no class-level adapter is set
- Generated methods resolve adapter from the class instead of
referencing Cacheable directly
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
By default, all classes use the global adapter set via `Cacheable.cache_adapter`. If you need a specific class to use a different cache backend, you can set one directly on the class:
260
+
261
+
```ruby
262
+
classFrequentlyAccessedModel
263
+
includeCacheable
264
+
265
+
self.cache_adapter =MyFasterCache.new
266
+
267
+
cacheable :expensive_lookup
268
+
269
+
defexpensive_lookup
270
+
# ...
271
+
end
272
+
end
273
+
```
274
+
275
+
The class-level adapter takes precedence over the global adapter. Classes without their own adapter fall back to `Cacheable.cache_adapter` as usual.
276
+
257
277
### Flexible Options
258
278
259
279
You can use the same options with multiple cache methods or limit them only to specific methods:
Cacheable.cache_adapter.fetch(__send__(method_names[:key_format_method_name], *args, **kwargs),opts[:cache_options])do# rubocop:disable Lint/UselessDefaultValueArgument -- not Hash#fetch; second arg is cache options (e.g. expires_in) passed to the adapter
adapter.fetch(__send__(method_names[:key_format_method_name], *args, **kwargs),opts[:cache_options])do# rubocop:disable Lint/UselessDefaultValueArgument -- not Hash#fetch; second arg is cache options (e.g. expires_in) passed to the adapter
0 commit comments