Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added (very) basic delegation which allows the system to fallback to …
…AR finders on cache misses
- Loading branch information
Tobias Lütke
committed
Jun 8, 2009
1 parent
8800202
commit 1383e82
Showing
12 changed files
with
262 additions
and
93 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,27 +1,29 @@ | ||
require 'rubygems' unless ENV['NO_RUBYGEMS'] | ||
%w[rake rake/clean fileutils newgem rubigen].each { |f| require f } | ||
require File.dirname(__FILE__) + '/lib/cached' | ||
|
||
# Generate all the Rake tasks | ||
# Run 'rake -T' to see list of generated tasks (from gem root directory) | ||
$hoe = Hoe.new('cached', Cached::VERSION) do |p| | ||
p.developer('Tobias Lütke', 'tobi@leetsoft.com') | ||
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n") | ||
p.extra_deps = [ | ||
['activesupport','>= 2.3.2'], | ||
] | ||
|
||
p.extra_dev_deps = [ | ||
['newgem', ">= #{::Newgem::VERSION}"] | ||
] | ||
p.clean_globs |= %w[**/.DS_Store tmp *.log] | ||
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}" | ||
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc') | ||
p.rsync_args = '-av --delete --ignore-errors' | ||
end | ||
|
||
require 'newgem/tasks' # load /tasks/*.rake | ||
Dir['tasks/**/*.rake'].each { |t| load t } | ||
|
||
# TODO - want other tests/tasks run by default? Add them to the list | ||
# task :default => [:spec, :features] | ||
BEGIN {$VERBOSE = false} | ||
|
||
require 'rubygems' unless ENV['NO_RUBYGEMS'] | ||
%w[rake rake/clean fileutils newgem rubigen].each { |f| require f } | ||
require File.dirname(__FILE__) + '/lib/cached' | ||
|
||
# Generate all the Rake tasks | ||
# Run 'rake -T' to see list of generated tasks (from gem root directory) | ||
$hoe = Hoe.new('cached', Cached::VERSION) do |p| | ||
p.developer('Tobias Lütke', 'tobi@leetsoft.com') | ||
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n") | ||
p.extra_deps = [ | ||
['activesupport','>= 2.3.2'], | ||
] | ||
|
||
p.extra_dev_deps = [ | ||
['newgem', ">= #{::Newgem::VERSION}"] | ||
] | ||
p.clean_globs |= %w[**/.DS_Store tmp *.log] | ||
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}" | ||
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc') | ||
p.rsync_args = '-av --delete --ignore-errors' | ||
end | ||
|
||
require 'newgem/tasks' # load /tasks/*.rake | ||
Dir['tasks/**/*.rake'].each { |t| load t } | ||
|
||
# TODO - want other tests/tasks run by default? Add them to the list | ||
# task :default => [:spec, :features] |
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,14 +1,18 @@ | ||
module Cached | ||
class Config | ||
attr_accessor :indexes, :class_name, :primary_key | ||
attr_accessor :indexes, :class_name, :primary_key, :delegates | ||
|
||
def initialize(class_name, primary_key) | ||
@indexes, @class_name, @primary_key = [], class_name.to_s, primary_key.to_s | ||
@delegates, @indexes, @class_name, @primary_key = [], [], class_name.to_s, primary_key.to_s | ||
end | ||
|
||
def index(*args) | ||
@indexes.push [args].flatten | ||
@indexes.push args.flatten | ||
end | ||
|
||
def delegate_to(*methods) | ||
@delegates += methods.flatten | ||
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Cached | ||
module Record | ||
|
||
def self.included?(base) | ||
|
||
if base.respond_to?(:save) | ||
base.alias_method_chain :save, :cached | ||
end | ||
|
||
end | ||
|
||
|
||
def save_with_cached | ||
save_without_cached | ||
|
||
# expire the cache, the object will be stored in it's prestine form | ||
# after the next lookup call hopefull. | ||
expire_object_in_cache | ||
|
||
# update the indexes for the new values. | ||
store_indexes_in_cache | ||
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,12 @@ | ||
require 'active_record' | ||
|
||
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => '/tmp/people.db') | ||
|
||
ActiveRecord::Schema.define do | ||
|
||
create_table :people, :force => true do |t| | ||
t.column :first_name, :string | ||
t.column :last_name, :string | ||
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.