prosto_cache 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,25 +1,49 @@
1
1
  = prosto_cache
2
2
 
3
- This library provides a simple way to cache model and to access this cache in some canonical way.
4
- Any changes to the model's objects will automatically result in cache reload.
5
- Cache reload in other ruby processes of same app will be triggered as well, but with some delay (currently up to 60 seconds).
6
- If delay in cache reloading is not an option, well, this simply library will not work for you, and you have to use something fancier, like Memcached.
3
+ prosto_cache provides a simple way to cache enumeration-like models in memory and to access this cache in uniform way.
4
+
5
+ Here are couple thinks that it will NOT do for you.
6
+
7
+ - it will not monkey patch rails in attempt to make itself 'totally' easy to use
8
+ - it will not attempt to share/distribute cache
9
+ - it will not cook your breakfeast, it does one thing only, and that thing is in-memory cache
10
+
11
+ And that is a good thing. Why?
12
+
13
+ - next time you upgrade your rails things are not likely to break in spectacular way (well, at least not because of this gem)
14
+ - there is a possibility/plan to make it work even for those not using ActiveRecord
15
+ - and most of all - it keeps things SIMPLE (do not confuse with 'easy')
16
+
17
+ Here are main features of this library:
18
+
19
+ - cache is accessible in a map-like way, and you can choose and specify ONE way to contruct the key to that map
20
+ - access key can be simple or compound (multi-step)
21
+ - virtual/transient/non-db attributes can be used for keys
22
+ - all cache values are accessible as a plain array
23
+ - changes to the model's objects will automatically result in cache reload when saved to database
24
+ - cache reload in other ruby processes of same app will be triggered as well, but with some delay (currently up to 60 seconds).
25
+ - If delay in cache reloading is not an option for you, well, this library will not work for you, use something fancier, like Memcached.
26
+ - it is possible to invalidate cache by hand, although usually there is no reason to
7
27
 
8
28
  Usage:
9
- 1. add ProstoCache mixin to your model
29
+ 1. Add ProstoCache mixin to your model
10
30
  class YourModel < ActiveRecord::Base
11
31
  include ProstoCache
12
32
  2. Configure cache access keys (optional step, by default cache is accessed by key 'name')
13
33
  cache_accessor_keys %w(scope name)
14
- 3. Your model must have non-nullable column updated_at, add it in migration if it is missing (this field is used for invalidating cache in other ruby processes).
34
+ 3. Your model MUST have non-nullable column updated_at, add new migration with it if missing
35
+ (this field is used for invalidating cache in other ruby processes)
15
36
  4. Access cached model object in your code like this
16
37
  * Simple case of one key
17
38
 
18
39
  YourModel.cache[:key1]
19
- * Case of 2 or more keys where it is known ahead of time that all parent keys exist. Looks conventional, but is unreliable because brackets operation on nill will raise an error.
40
+ * Case of 2 or more keys where it is known ahead of time that all parent keys exist.
41
+ Looks conventional, but is not quite unreliable because brackets operation on nil will raise an error.
42
+ If you know a good way to make it reliable, let me know!
20
43
 
21
44
  YourModel.cache[:key1][:key2][:key3]
22
- * Case of 2 or more keys where any key may not be present in cache, and expected answer is nil. Looks so-so, but is much more reliable then previos use case.
45
+ * Case of 2 or more keys where any key may not be present in cache, and expected answer is nil.
46
+ Looks so-so, but is much more reliable then previos use case.
23
47
 
24
48
  YourModel.cache[[:key1, :key2, :key3]]
25
49
 
@@ -31,7 +55,9 @@ Usage:
31
55
  * Start a feature/bugfix branch
32
56
  * Commit and push until you are happy with your contribution
33
57
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
34
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
58
+ * Please try not to mess with the Rakefile, version, or history.
59
+ If you want to have your own version, or is otherwise necessary, that is fine, but please
60
+ isolate to its own commit so I can cherry-pick around it.
35
61
 
36
62
  == Copyright
37
63
 
data/lib/prosto_cache.rb CHANGED
@@ -120,10 +120,12 @@ module ProstoCache
120
120
  end
121
121
 
122
122
  def query_cache_signature
123
- raw_result = ActiveRecord::Base.connection.execute "select max(updated_at) as max_updated_at, max(id) as max_id, count(id) as count from #{model_class.name.tableize}"
123
+ raw_result = ActiveRecord::Base.connection.execute "select max(updated_at) as max_updated_at, max(id) as max_id, count(id) as count from #{model_class.table_name}"
124
124
  array_result = case raw_result.class.name
125
125
  when 'Mysql::Result'
126
126
  [].tap { |rows| raw_result.each_hash { |h| rows << h } }
127
+ when 'Mysql2::Result'
128
+ [].tap { |rows| raw_result.each(:as => :hash) { |h| rows << h } }
127
129
  when 'PGresult'
128
130
  raw_result.map(&:to_hash)
129
131
  else
data/prosto_cache.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "prosto_cache"
5
- s.version = "0.1.2"
5
+ s.version = "0.1.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Olek Poplavsky"]
9
- s.date = "2012-07-13"
9
+ s.date = "2011-05-23"
10
10
  s.description = "Use this gem if you want a simple 'enum-like' cache for your models that does not restrict updates, but will stay current with them."
11
11
  s.email = "olek@woodenbits.com"
12
12
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,97 +1,89 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: prosto_cache
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Olek Poplavsky
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-07-13 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2011-05-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hashie
16
+ requirement: !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 23
28
- segments:
29
- - 1
30
- - 0
31
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
32
21
  version: 1.0.0
33
- version_requirements: *id001
34
- name: hashie
35
- prerelease: false
36
22
  type: :runtime
37
- - !ruby/object:Gem::Dependency
38
- requirement: &id002 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
- requirements:
34
+ requirements:
41
35
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 2
46
- - 3
47
- - 0
36
+ - !ruby/object:Gem::Version
48
37
  version: 2.3.0
49
- version_requirements: *id002
50
- name: rspec
51
- prerelease: false
52
38
  type: :development
53
- - !ruby/object:Gem::Dependency
54
- requirement: &id003 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
55
41
  none: false
56
- requirements:
42
+ requirements:
57
43
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 19
60
- segments:
61
- - 1
62
- - 1
63
- - 0
64
- version: 1.1.0
65
- version_requirements: *id003
44
+ - !ruby/object:Gem::Version
45
+ version: 2.3.0
46
+ - !ruby/object:Gem::Dependency
66
47
  name: bundler
67
- prerelease: false
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.1.0
68
54
  type: :development
69
- - !ruby/object:Gem::Dependency
70
- requirement: &id004 !ruby/object:Gem::Requirement
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
71
57
  none: false
72
- requirements:
73
- - - "="
74
- - !ruby/object:Gem::Version
75
- hash: 49
76
- segments:
77
- - 0
78
- - 8
79
- - 7
80
- version: 0.8.7
81
- version_requirements: *id004
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ - !ruby/object:Gem::Dependency
82
63
  name: rake
83
- prerelease: false
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.8.7
84
70
  type: :development
85
- description: Use this gem if you want a simple 'enum-like' cache for your models that does not restrict updates, but will stay current with them.
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.8.7
78
+ description: Use this gem if you want a simple 'enum-like' cache for your models that
79
+ does not restrict updates, but will stay current with them.
86
80
  email: olek@woodenbits.com
87
81
  executables: []
88
-
89
82
  extensions: []
90
-
91
- extra_rdoc_files:
83
+ extra_rdoc_files:
92
84
  - LICENSE.txt
93
85
  - README.rdoc
94
- files:
86
+ files:
95
87
  - .rspec
96
88
  - Gemfile
97
89
  - Gemfile.lock
@@ -102,39 +94,32 @@ files:
102
94
  - prosto_cache.gemspec
103
95
  - spec/prosto_cache_spec.rb
104
96
  - spec/spec_helper.rb
105
- has_rdoc: true
106
97
  homepage: http://github.com/olek/prosto_cache
107
- licenses:
98
+ licenses:
108
99
  - MIT
109
100
  post_install_message:
110
101
  rdoc_options: []
111
-
112
- require_paths:
102
+ require_paths:
113
103
  - lib
114
- required_ruby_version: !ruby/object:Gem::Requirement
104
+ required_ruby_version: !ruby/object:Gem::Requirement
115
105
  none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: 3
120
- segments:
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ segments:
121
111
  - 0
122
- version: "0"
123
- required_rubygems_version: !ruby/object:Gem::Requirement
112
+ hash: 849790085734229441
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
114
  none: false
125
- requirements:
126
- - - ">="
127
- - !ruby/object:Gem::Version
128
- hash: 3
129
- segments:
130
- - 0
131
- version: "0"
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
132
119
  requirements: []
133
-
134
120
  rubyforge_project:
135
- rubygems_version: 1.6.2
121
+ rubygems_version: 1.8.24
136
122
  signing_key:
137
123
  specification_version: 3
138
124
  summary: Very simple caching for your ActiveRecord models.
139
125
  test_files: []
140
-