preheat 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +60 -0
  2. data/VERSION +1 -1
  3. data/lib/preheat.rb +2 -4
  4. data/preheat.gemspec +46 -0
  5. metadata +5 -4
@@ -0,0 +1,60 @@
1
+ = Preheat
2
+
3
+ IN DEVELOPMENT DISCLAMER: This gem is still under development and hasn't been put through intensive real-world testing yet. Any comments/concerns/recommendations would be greatly appreciated.
4
+
5
+ Keep your Rails.cache up to date without:
6
+ * code bloat in your Rails.cache.fetch invocations
7
+ * tedious dependency setup in a cron task to mimic what your controller does, just so you can call your model/library methods which have the Rails.cache.fetch invocations
8
+
9
+ Anything executed in a Preheat.it block will change all fetch calls into a fetch calls with :force => true. (:force => true will force a cache-miss and a subsequent cache-write)
10
+
11
+ == Example
12
+
13
+ This will "preheat" all your Rails.cache.fetch calls on your homepage. It is as simple as that!
14
+
15
+ Preheat.it do
16
+ app.get("/")
17
+ end
18
+
19
+ Note: If you have not seen "app.get" used before, the "app" object is not related to my preheat gem. It ships with rails: {more detail here}[http://www.clarkware.com/cgi/blosxom/2006/04/04]. I use app.get because ActiveSupport's fetch method is being modified only in the ruby process which is using Preheat, so something like mechanize/wget/curl would call the page through your frontend webserver and would not be effected by Preheat.it, while app.get will directly call your controller in that same ruby process.
20
+
21
+ == A more detailed example
22
+
23
+ Let's say we have a list of product pages where we want the cached to be updated every hour.
24
+
25
+ #app/models/product.rb
26
+ def slow_method
27
+ Rails.cache.fetch("product-slow-method-#{self.id}") do
28
+ sleep 15
29
+ Time.now
30
+ end
31
+ end
32
+
33
+ #lib/tasks/preheat.rake
34
+ namespace :preheat do
35
+ desc "Preheat product caches"
36
+ task (:products => :environment) do
37
+ Preheat.it do
38
+ Product.all.each do |product|
39
+ app.get(app.products_path(product)) #or you could just call product.slow_method directly, whatever makes more sense
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ #crontab -e
46
+ 0 * * * * /path/to/rake preheat:products RAILS_ENV=production 2>&1 >> #{Rails.root}/log/preheat.log &
47
+
48
+ == Installation
49
+
50
+ 1. gem install preheat
51
+ 2. Add the gem to environment.rb or your Gemfile
52
+
53
+ == Thanks
54
+
55
+ John Hume for helping me cleanup part of my code.
56
+ Brian Guthrie for getting me all learned up on gem dependencies and the like.
57
+
58
+
59
+
60
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -11,14 +11,12 @@ class ActiveSupport::Cache::Store
11
11
  end
12
12
  end
13
13
 
14
- #the singleton class_eval workaround for the aliasing is due to this issue:
15
- # http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.ruby/2006-05/msg00575.html
16
14
  def enable_preheat
17
- (class << self; self; end).class_eval { alias_method_chain :fetch, :force }
15
+ self.class_eval { alias_method_chain :fetch, :force }
18
16
  end
19
17
 
20
18
  def disable_preheat
21
- (class << self; self; end).class_eval { alias_method :fetch, :fetch_without_force }
19
+ self.class_eval { alias_method :fetch, :fetch_without_force }
22
20
  end
23
21
  end
24
22
 
@@ -0,0 +1,46 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{preheat}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tom Hallett"]
12
+ s.date = %q{2010-10-07}
13
+ s.description = %q{Keep your Rails.cache warm}
14
+ s.email = %q{tomhallett@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "lib/preheat.rb",
24
+ "preheat.gemspec",
25
+ "spec/lib/preheat_spec.rb"
26
+ ]
27
+ s.homepage = %q{http://github.com/tommyh/preheat}
28
+ s.rdoc_options = ["--charset=UTF-8"]
29
+ s.require_paths = ["lib"]
30
+ s.rubygems_version = %q{1.3.7}
31
+ s.summary = %q{Keep your Rails.cache warm}
32
+ s.test_files = [
33
+ "spec/lib/preheat_spec.rb"
34
+ ]
35
+
36
+ if s.respond_to? :specification_version then
37
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
+ else
42
+ end
43
+ else
44
+ end
45
+ end
46
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preheat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tom Hallett
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-28 00:00:00 -04:00
18
+ date: 2010-10-07 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -33,6 +33,7 @@ files:
33
33
  - Rakefile
34
34
  - VERSION
35
35
  - lib/preheat.rb
36
+ - preheat.gemspec
36
37
  - spec/lib/preheat_spec.rb
37
38
  has_rdoc: true
38
39
  homepage: http://github.com/tommyh/preheat