-
-
Notifications
You must be signed in to change notification settings - Fork 52
Description
While I was shooting the caching unit for the Phlex on Rails course, I was surprised about the behavior of the cache.
Here's the commit where I discovered the issue: thingybase/server@c9a416f
To recreate, spin up a Rails app, use cache in any Phlex component in Rails, then run rails dev:cache to enable the cache. You'll get an exception from this block:
# Override this method to use a different cache store.
private def cache_store
raise "Cache store not implemented."
endThis surprised me for a few reasons.
- I assumed from the docs Phlex caching in Rails would use the in-memory FIFO store (https://www.phlex.fun/components/caching.html)
- When I enabled the cache, I was surprised to see the exception message.
I think a reasonable behavior, in terms of "least surprises", is to add this into Components::Base by default, or equivalent.
class Components::Base
def cache_store
Rails.cache
end
endAdditionally, I don't think this is implemented correctly in phlex-rails
def low_level_cache(...)
Rails.application.config.action_controller.perform_caching ? super : yield
endI get that this "disables caching", but I think the correct behavior would be to delegate this to Rails's cache store and let it handle what to do when a value is disabled or enabled.
I ran into this problem when I was trying to diagnose an issue with my cache not working that ended up not being a bug (I enabled cache for a different Raisl project 🤣)
What I'd propose for the "fix" is something like this:
- Delete the
low_level_cachemethod in phlex-rails and letcache_storehandle no-ops. - Either patch
cache_storein thephlex-railsgem to include Rails.cache (principle of least surprise) or include it in the generator.
I can put all of this into a PR, but wanted to check on here first to make sure I'm not overlooking some sort of default behavior.