Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Arjeno/caches-page
Caches page
- Loading branch information
Showing
30 changed files
with
571 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,60 @@ | ||
require 'catche/controller/base' | ||
module Catche | ||
module Controller | ||
|
||
extend ActiveSupport::Concern | ||
extend ActiveSupport::Autoload | ||
|
||
eager_autoload do | ||
autoload :Action | ||
autoload :Page | ||
end | ||
|
||
include Action, Page | ||
|
||
included do | ||
|
||
class_attribute :catche_model, | ||
:catche_resource_name, | ||
:catche_constructed_tags | ||
|
||
end | ||
|
||
module ClassMethods | ||
|
||
# Caches a controller action. | ||
# | ||
# catche Project, :index, :resource_name => :project | ||
def catche(model, *args) | ||
options = args.extract_options! | ||
|
||
self.catche_model = model | ||
self.catche_resource_name = options[:resource_name] || self.catche_model.name.downcase.to_sym | ||
|
||
case options[:type] | ||
when :page then caches_page *args, options | ||
else caches_action *args, options | ||
end | ||
end | ||
|
||
def catche? | ||
self.catche_model.present? | ||
end | ||
|
||
end | ||
|
||
def catche_tags | ||
return @catche_tags if ! @catche_tags.nil? | ||
|
||
if resource = Catche::ResourceLoader.fetch_one(self, self.class.catche_resource_name) | ||
tags = Catche::Tag::Collect.resource(resource) | ||
@catche_tags = tags[:set] | ||
else | ||
tags = Catche::Tag::Collect.collection(self, self.class.catche_model) | ||
@catche_tags = tags[:set] | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
||
ActionController::Base.send :include, Catche::Controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Catche | ||
module Controller | ||
module Action | ||
|
||
extend ActiveSupport::Concern | ||
|
||
module ClassMethods | ||
|
||
# Caches an action in Rails.cache | ||
# See ActionController `caches_action` for more information | ||
# | ||
# catches_action Project, :index | ||
def catches_action(model, *args) | ||
catche model, *args, :type => :action | ||
end | ||
|
||
end | ||
|
||
def _save_fragment(name, options={}) | ||
if self.class.catche? | ||
key = fragment_cache_key(name) | ||
Catche::Tag.tag_view! key, *catche_tags | ||
end | ||
|
||
super | ||
end | ||
|
||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Catche | ||
module Controller | ||
module Page | ||
|
||
extend ActiveSupport::Concern | ||
|
||
module ClassMethods | ||
|
||
# Caches an action by file | ||
# See ActionController `caches_page` for more information | ||
# | ||
# catches_action Project, :index | ||
def catches_page(model, *args) | ||
catche model, *args, :type => :page | ||
end | ||
|
||
def cache_page(content, path, extension = nil, gzip = Zlib::BEST_COMPRESSION) | ||
if self.catche? | ||
Catche::Tag.tag_page! page_cache_path(path, extension), *catche_constructed_tags | ||
end | ||
|
||
super | ||
end | ||
|
||
end | ||
|
||
def cache_page(content = nil, options = nil, gzip = Zlib::BEST_COMPRESSION) | ||
self.class.catche_constructed_tags = catche_tags | ||
super | ||
end | ||
|
||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'catche/expire/view' | ||
require 'catche/expire/page' | ||
|
||
module Catche | ||
module Expire | ||
|
||
class << self | ||
|
||
def expire!(data) | ||
Catche::Expire::View.expire! *data[:views] | ||
Catche::Expire::Page.expire! *data[:pages] | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Catche | ||
module Expire | ||
module Page | ||
|
||
class << self | ||
|
||
# Expires cache by deleting the associated files | ||
# Uses the same flow as defined in `expire_page` in ActionController | ||
# | ||
# Catche::Expire::Page.expire!('/public/projects.html') | ||
def expire!(*paths) | ||
paths.each do |path| | ||
File.delete(path) if File.exist?(path) | ||
File.delete(path + '.gz') if File.exist?(path + '.gz') | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Catche | ||
module Expire | ||
module View | ||
|
||
class << self | ||
|
||
# Expires cache by deleting the associated keys | ||
# | ||
# Catche::Expire::View.expire!('projects') | ||
def expire!(*keys) | ||
keys.each do |key| | ||
Catche.adapter.delete key | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.