ahawkins / cashier Goto Github PK
View Code? Open in Web Editor NEWTag based caching for Rails using Redis. Associate different cached content with a tag, then expire by tag instead of key.
License: MIT License
Tag based caching for Rails using Redis. Associate different cached content with a tag, then expire by tag instead of key.
License: MIT License
I'm trying to use this Gem with no luck - I can't figure out from the documentation if I'm using it correctly.
I have an products index, with various combinations of query strings. I would like to cache these all under a tag, and then clear all cached items in a tag when a product is changed, removed or added.
In my Products controller I have:
class ProductsController < ApplicationController
caches_action :index, :cache_path => Proc.new { |c| c.params }, :tag => "products"
cache_sweeper :product_sweeper #Products sweeper will use Cashier.expire "products" if needed
def index
# rest of code
end
end
When trying to use Cashier as above, I get the following:
uninitialized class variable @@adapter in Cashier
What am I doing wrong? Any help would be greatly appreciated.
In application.rb, I define a "current_user" method, which is necessary for how I do authentication (SimplestAuth) & authorization (declarative_authorization).
When I add cashier to my Gemfile and run bundle install
, suddenly I start getting 500's and a NoMethodError for current_user. Reverting the Gemfile and removing the vendored cashier gem — and making no other changes — makes the NoMethodError go away again.
Trying to use this cool gem, but I am struggling starting my application with it (am I missing something simple here?).
I added the cashier gem to my Gemfile and I also added the following to my development.rb file:
config.cashier.adapter.redis = REDIS_OBJ_HERE
I am getting the following error when running my rails server:
undefined method `cashier' for #<Rails::Application::Configuration:0x007fdfd11bdc18>
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/railties-3.2.6/lib/rails/railtie/configuration.rb:85:in `method_missing'
/Users/michael/Projects/mixellent/config/environments/development.rb:58:in `block in <top (required)>'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/railties-3.2.6/lib/rails/railtie/configurable.rb:24:in `class_eval'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/railties-3.2.6/lib/rails/railtie/configurable.rb:24:in `configure'
/Users/michael/Projects/mixellent/config/environments/development.rb:1:in `<top (required)>'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `block in require'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/railties-3.2.6/lib/rails/engine.rb:571:in `block in <class:Engine>'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `instance_exec'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `run'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/railties-3.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `each'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `run_initializers'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/railties-3.2.6/lib/rails/application.rb:136:in `initialize!'
/Users/michael/.rvm/gems/ruby-1.9.3-p0@rails326/gems/railties-3.2.6/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/michael/Projects/mixellent/config/environment.rb:5:in `<top (required)>'
Note: I am using Rails 3.2.6 on Ruby 1.9.3.
Thanks,
Michael
Hey,
I want to add integration to Rails.cache through cachier.
Meaning, every time you call Rails.cache.fetch with tags, you will go through cashier, also, every time you delete a cache key, you invalidate the tags for it.
What do you think is the best way to integrate through Rails.cache?
I tried opening the dalli_store class but it fails for some reason.
Would love your thoughts.
The code at https://github.com/ahawkins/cashier/blob/master/lib/cashier/railtie.rb#L6 raises a deprecation warning with rails 4.2.1 as the cache.instrument has been deprecated:
"ActiveSupport::Cache.instrument is deprecated and will be removed in Rails 5. Instrumentation is now always on so you can safely stop using it."
Just a minor thing, but will break support with rails 5.
Would love to see a notification set up for when a tag gets expired. I particularly use the notifications for outputting to my logs, which is the most common method i use on cashier that would be nice to have notification on. Does this fit the expected use of the notifications?
Trying to set a tag in a controller action with a proc won't work
caches_action :tag => proc {|c|
# c is the controller
"users/#{c.current_user.id}/dashboard"
}
There's no code within action pack (Rails 3.2.9) that will evaluate a proc for tag. It just gets past along as a store_option which you can see here. There also doesn't seem to be a way to evaluate the proc later on in the cashier code because you don't have the controller to execute it from.
In previous versions of Rails did all procs passed to caches_action get evaluated somewhere?
Can you take a look at Rallysf branch and see about pulling in some of their commits?
I believe rallysf@8ac3725 will solve issues #6 and #8.
Just stumbled across a weird issue - when installing the Gem, it seems I'm not able to access any methods defined in ApplicationController from other controllers. Any ideas why this would happen?
The currently released version of the gem (0.4.0) doesn't work unless I open up the downloaded gem, and add
ActiveSupport::Cache::Store.instrument = true
ActiveSupport::Notifications.subscribe("cache_write.active_support") do |*args|
payload = ActiveSupport::Notifications::Event.new(*args).payload
Cashier.store_fragment payload[:key], payload[:tag] if payload[:tag]
end
to the bottom of lib/cashier.rb. If I instead point my Gemfile to your git repo then Cashier works. I notice there's a couple of weeks difference between the last gem release and when you added the above lines to lib/cashier.rb.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.