kv_cache 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98d7e292a3f0eba04afbd9089e994a9cd8c02e7c
4
- data.tar.gz: 9b97bef336dca52763083d14112732e02d7eec60
3
+ metadata.gz: 07bcbff9052f9d411d0fd517ac6792d8156bda03
4
+ data.tar.gz: 5c5ee3df4b68ec5a91a9ff0b8b0038c8cd146e8e
5
5
  SHA512:
6
- metadata.gz: e98482c5e0a48fa4a9a2813657a2c333eb113fc41b0b4c476fd70078382d233bc1ed2f7c9e7ad0d7e04dfa71ebe3b1704e906f70206eef569ecdb11299d31c02
7
- data.tar.gz: 3b32af285222b85ac45833eeda9430db81ee8b6a590a54f464ab1d3188b2815ef9bba55bd7fed3781b0c10b52d5bb8d3ae059db337a06a3ab1af4ec5d00b0abb
6
+ metadata.gz: ade0ae3863fcae43c520d752da49b70a2c99336b2531b9b7632e96fd7ef66c0d4fb2bd3f80d2d6c35aa4c956c221a7258396905000da3a3a45efcdb30c216ead
7
+ data.tar.gz: 470eb49e7459fe054879f4ec60904906857ae0d39599d14bb2d4936762ab4b3cb4cb0e0696c69c1e4a905b90fae8102aede04a047575bc924d10887dc3f85307
data/README.md CHANGED
@@ -20,16 +20,18 @@ Or install it yourself as:
20
20
  ## Usage
21
21
 
22
22
  ```
23
- require 'kv_cache'
23
+ #config
24
+ opts = { :namespace => "app_v2", :compress => true }
25
+ KvCache::Store.storer = Dalli::Client.new('127.0.0.1:11211', opts)
24
26
 
27
+ #class
25
28
  class City < ActiveRecord::Base
26
29
  attr_accessible :name, :province
27
30
  include KvCache
28
31
 
29
- # kv_cache :method_name, expire_time, :key, values_lambda
30
- scope :guangxi, ->{ puts "fecth from db"
31
- Store.call {where(province: "guangxi")} }
32
-
32
+ def of_province(prv)
33
+ Store.call("#City.of_province:#{prv}") {where(province: prv)}
34
+ end
33
35
  after_save :kv_cache_reset
34
36
 
35
37
  def kv_cache_reset
@@ -38,12 +40,12 @@ class City < ActiveRecord::Base
38
40
  end
39
41
 
40
42
  # some code
41
- City.guangxi # first call will :
43
+ City.of_province("guangxi") # first call will :
42
44
  # fecth from db
43
45
  # select * from cities where province = 'guangxi'
44
- cs = City.guangxi # will just return result above
46
+ cs = City.of_province("guangxi") # will just return result above
45
47
  cs.first.save # will kv_cache_reset("guangxi")
46
- City.guangxi # fecth from db again
48
+ City.of_province("guangxi") # fecth from db again
47
49
 
48
50
  ```
49
51
 
@@ -1,3 +1,3 @@
1
1
  module KvCache
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -69,4 +69,18 @@ describe "KvCache::Store" do
69
69
  res.should == 90
70
70
  KvCache::Store.delete("hello")
71
71
  end
72
+
73
+ it "#call auto Serializable" do
74
+ key = "Serializable"
75
+ KvCache::Store.delete(key)
76
+ res = KvCache::Store.call(key, 20) do
77
+ { a: 9, b: 8}
78
+ end
79
+ res2 = KvCache::Store.call(key, 20) do
80
+ { a: 9, b: 8}
81
+ end
82
+ res2.should be_kind_of(Hash)
83
+ res2[:b].should == 8
84
+ KvCache::Store.delete(key)
85
+ end
72
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kv_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - azhao1981
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-20 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler