Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update for Rails 3.2 compatibility #1

Merged
merged 1 commit into from

4 participants

@boffbowsh

.cache_page can take an optional gzip compression level, but we want to ignore this as we only ever use raw: true

@matsadler

looks good to me

lib/memcaches_page.rb
@@ -8,7 +8,8 @@ def cache_page(content, path, options={})
end
end
- def cache_page(content = nil, options = {})
+ def cache_page(content = nil, *args)
+ options = args.extract_options!
@mmazour
mmazour added a note

Is this right? My reading of the API is that extract_options! gives you what you want if options is the last argument, but for cache_page the last argument's the gzip level. (I think)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@boffbowsh

Reading the Rails 3.2 API more closely it looks like they've broken the API completely for caches_page. I think I'll make this a proper breaking change and introduce memcaches_page instead so the intention is clear.

Paul Bowsher Update for Rails 3.2 compatibility
Remove from the Rails `cache_page` pipeline 
entirely to avoid conflicts with the new gzip 
options in Rails 3.2
64e132e
@boffbowsh

Updated. Usable now with memcaches_page instead of caches_page. Tested with Member service locally.

@timblair
Owner

:+1:

@boffbowsh boffbowsh merged commit 33c2d80 into master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 11, 2013
  1. Update for Rails 3.2 compatibility

    Paul Bowsher authored
    Remove from the Rails `cache_page` pipeline 
    entirely to avoid conflicts with the new gzip 
    options in Rails 3.2
This page is out of date. Refresh to see the latest.
View
5 CHANGELOG.md
@@ -1,5 +1,10 @@
# MemcachesPage Gem Changelog
+## 0.x.x - 2013/03/xx
+ * **Backwards-incompatible change**: Now called using `memcaches_page`. See
+README for details.
+ * Update for compatibility with Rails 3.2
+
## 0.1.3 - 2012/09/20
* Allow passing through options to `Rails.cache.write`, e.g. `cache_page expires_in: 5.minutes`
View
16 README.md
@@ -1,6 +1,7 @@
# MemcachesPage
-Overrides `caches_page` and stores in memcached instead. Uses configuration from Rails cache store.
+Overrides `caches_page` and stores in memcached instead. Uses configuration from
+Rails cache store.
## Installation
@@ -24,11 +25,12 @@ Or install it yourself as:
config.cache_store :dalli_store, ['memcache.dev:11211'], expires_in: 604800, namespace: "site"
```
-Note, ensure compression isn't used, or if you do configure nginx to inflate it before serving.
+Note, ensure compression isn't used, or if you do configure nginx to inflate it
+before serving.
### Caching
-In your controller (or `ApplicationController`), simply include the module:
+Include the module in your `ApplicationController`:
```ruby
class ApplicationController < ActionController::Base
@@ -36,7 +38,13 @@ class ApplicationController < ActionController::Base
end
```
-Then use `caches_page` as normal.
+Then use `memcaches_page` in a similar way to `caches_page`:
+
+```ruby
+class SiteController < ApplicationController
+ memcaches_page :index, :show, unless: -> { |c| c.current_user.nil? }
+end
+```
## Contributing
View
15 lib/memcaches_page.rb
@@ -1,15 +1,24 @@
module MemcachesPage
extend ActiveSupport::Concern
module ClassMethods
- def cache_page(content, path, options={})
+ def memcaches_page(*actions)
+ return unless perform_caching
+ options = actions.extract_options!
+
+ after_filter({:only => actions}.merge(options)) do |c|
+ c.memcache_page
+ end
+ end
+
+ def memcache_page(content, path, options={})
return unless perform_caching
Rails.cache.write path.gsub('%', '%25'), content, options.merge(raw: true)
end
end
- def cache_page(content = nil, options = {})
+ def memcache_page(options = {})
return unless self.class.perform_caching && caching_allowed? && !request.params.key?('no-cache')
- self.class.cache_page(content || response.body, request.fullpath, options)
+ self.class.memcache_page(response.body, request.fullpath, options)
end
end
View
2  memcaches_page.gemspec
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
gem.summary = %q{Uses configuration from Rails cache store.}
gem.homepage = ""
- gem.add_dependency("rails", "~> 3.1")
+ gem.add_dependency("rails", "~> 3.2")
gem.files = `git ls-files`.split($\)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
Something went wrong with that request. Please try again.