Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
caching architecture and writes response to filesystem
- Loading branch information
Dan Pickett
committed
Nov 4, 2008
1 parent
6a02c98
commit 02741b5
Showing
12 changed files
with
372 additions
and
216 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
require "amazon/ecs" | ||
require "amazon/element" | ||
require "amazon/response" | ||
require "amazon/cache_factory" | ||
|
||
require "amazon/caching_strategy" | ||
require "amazon/configuration_error" |
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 @@ | ||
class Amazon::CacheFactory | ||
def self.cache(request, response, options) | ||
strategy_class_hash[options[:caching_strategy]].cache(request, response, options) | ||
end | ||
|
||
def self.validate(options) | ||
#check for a valid caching strategy | ||
unless self.strategy_class_hash.keys.include?(options[:caching_strategy]) | ||
raise Amazon::ConfigurationError, "Invalid caching strategy" | ||
end | ||
strategy_class_hash[options[:caching_strategy]].validate(options) | ||
end | ||
|
||
private | ||
def self.strategy_class_hash | ||
{ | ||
:filesystem => Amazon::CachingStrategy::Filesystem | ||
} | ||
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,4 @@ | ||
module CachingStrategy | ||
require File.join(File.dirname(__FILE__), "caching_strategy/base") | ||
require File.join(File.dirname(__FILE__), "caching_strategy/filesystem") | ||
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,11 @@ | ||
module Amazon::CachingStrategy | ||
class Base | ||
def self.cache(request, response, options) | ||
raise "This method must be overwritten by a caching strategy" | ||
end | ||
|
||
def self.validate(options) | ||
raise "This method must be overwritten by a caching strategy" | ||
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,23 @@ | ||
module Amazon::CachingStrategy | ||
class Filesystem < Amazon::CachingStrategy::Base | ||
def self.cache(request, response, options) | ||
path = options[:caching_options][:cache_path] | ||
cached_filename = Digest::SHA1.hexdigest(response.request_url) | ||
|
||
cached_file = File.open(File.join(path, cached_filename), "w") | ||
cached_file.puts response.doc.to_s | ||
cached_file.close | ||
end | ||
|
||
def self.validate(options) | ||
#check for required options | ||
if options[:caching_options].nil? | ||
raise Amazon::ConfigurationError, "You must specify caching options for filesystem caching: :cache_path is required" | ||
end | ||
|
||
if options[:caching_options][:cache_path].nil? || !File.directory?(options[:caching_options][:cache_path]) | ||
raise Amazon::ConfigurationError, "You must specify a cache path for filesystem caching" | ||
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
Oops, something went wrong.