lawnchair 0.5.2 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,7 +10,7 @@ Lawnchair includes a Rails view helper that can be used to cache the rendered vi
10
10
 
11
11
  == Usage Examples
12
12
 
13
- All you really need to do is wrap some expensive piece of Ruby code in the Lawnchair::Cache.me method as a block and it will be evaluated and the return value will cached in the given cache key.
13
+ All you really need to do is wrap some expensive piece of Ruby code in the Lawnchair.cache method as a block and it will be evaluated and the return value will cached in the given cache key.
14
14
 
15
15
  MAKE SURE REDIS SERVER IS RUNNING PRIOR TO TRYING ANYTHING BELOW!!!
16
16
 
@@ -24,7 +24,7 @@ This will connect to a default database on localhost, if you want to connect to
24
24
 
25
25
  Obligatory example:
26
26
 
27
- Lawnchair::Cache.me("cache_key2") do
27
+ Lawnchair.cache("cache_key2") do
28
28
  # ideally this would be something a little more computationally expensive, but sleep will have to do
29
29
  (1..3).inject([]) do
30
30
  |set, i| set << Time.now.strftime("%H:%M:%S")
@@ -41,7 +41,7 @@ Now, since it is cached, any time this block method is called (for the next 60 m
41
41
 
42
42
  If an hour is too long, or short for the cache key expiration you can set that to anything you want using the :expires_in hash key and entering a time in seconds
43
43
 
44
- Lawnchair::Cache.me("cache_key", :expires_in => 1.day) do
44
+ Lawnchair.cache("cache_key", :expires_in => 1.day) do
45
45
  # expensive code to be cached for 24 hours
46
46
  end
47
47
 
@@ -55,7 +55,7 @@ Available options:
55
55
  If you want to get really fancy you can cache the values in process as well as in Redis. This can be a fairly significant win
56
56
  if you are running the Redis server on a different physical machine as all network latency is taken out of the equation, especially if you are hitting a cache key many times on the same request. Also, it's probably best not to store TONS of keys in there, as your ruby process can bloat fairly quickly if you put everything in there. Also, these will persist as long as the process is running, unless you manually expire it.
57
57
 
58
- Lawnchair::Cache.me("cache_key3", :in_process => true) do
58
+ Lawnchair.cache("cache_key3", :in_process => true) do
59
59
  # expensive code to be cached in process AND in redis
60
60
  end
61
61
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.4
data/lawnchair.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lawnchair}
8
- s.version = "0.5.2"
8
+ s.version = "0.5.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Shane Wolf"]
data/lib/lawnchair.rb CHANGED
@@ -11,8 +11,10 @@ if defined? RAILS_ENV
11
11
  end
12
12
 
13
13
  module Lawnchair
14
- class Cache
15
- def self.me(key, options={}, &block)
14
+ class << self
15
+ attr_reader :redis
16
+
17
+ def cache(key, options={}, &block)
16
18
  if options[:in_process]
17
19
  store = Lawnchair::StorageEngine::Composite.new(:in_process, :redis)
18
20
  else
@@ -20,10 +22,6 @@ module Lawnchair
20
22
  end
21
23
  store.fetch(key, options, &block)
22
24
  end
23
- end
24
-
25
- class << self
26
- attr_reader :redis
27
25
 
28
26
  def connectdb(redis=nil)
29
27
  @redis = (redis || Redis.new(:db => 11))
@@ -33,4 +31,12 @@ module Lawnchair
33
31
  redis.flushdb
34
32
  end
35
33
  end
34
+
35
+ class Cache
36
+ # <b>DEPRECATED:</b> Please use <tt>Lawnchair.cache</tt> instead.
37
+ def self.me(key, options={}, &block)
38
+ warn "[DEPRECATION] 'Lawnchair::Cache.me' is deprecated. Please use 'Lawnchair.cache' instead."
39
+ Lawnchair.cache(key, options, &block)
40
+ end
41
+ end
36
42
  end
data/lib/view/helper.rb CHANGED
@@ -3,7 +3,7 @@ module Lawnchair
3
3
  module View
4
4
  module Helper
5
5
  def lawnchair_cache(key, &block)
6
- rendered_value = Lawnchair::Cache.me(key, :raw => true) do
6
+ rendered_value = Lawnchair.cache(key, :raw => true) do
7
7
  capture(&block)
8
8
  end
9
9
  concat(rendered_value)
@@ -4,15 +4,15 @@ describe "Lawnchair::Cache" do
4
4
  describe ".me" do
5
5
  it "returns the value if it exists" do
6
6
  expected_object = [1,2,3,4]
7
- Lawnchair::Cache.me("marshalled_array") { expected_object }
7
+ Lawnchair.cache("marshalled_array") { expected_object }
8
8
 
9
- x = Lawnchair::Cache.me("marshalled_array") { "JUNK DATA" }
9
+ x = Lawnchair.cache("marshalled_array") { "JUNK DATA" }
10
10
  x.should == expected_object
11
11
  end
12
12
 
13
13
  it "marshalls the object into redis" do
14
14
  expected_object = [1,2,3,4]
15
- Lawnchair::Cache.me("marshalled_array") { expected_object }
15
+ Lawnchair.cache("marshalled_array") { expected_object }
16
16
 
17
17
  Marshal.load(Lawnchair.redis["Lawnchair:marshalled_array"]).should == [1,2,3,4]
18
18
  end
@@ -23,7 +23,7 @@ describe "Lawnchair::Cache" do
23
23
  Lawnchair::StorageEngine::Composite.stub!(:new).and_return(mock_composite_engine)
24
24
 
25
25
  mock_composite_engine.should_receive(:fetch)
26
- Lawnchair::Cache.me("mu", :in_process => true, :raw => true) { "fasa" }
26
+ Lawnchair.cache("mu", :in_process => true, :raw => true) { "fasa" }
27
27
  end
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lawnchair
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Wolf