m4dbi 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/m4dbi/model.rb +12 -0
  2. data/lib/m4dbi/version.rb +1 -1
  3. metadata +2 -2
data/lib/m4dbi/model.rb CHANGED
@@ -38,6 +38,18 @@ module M4DBI
38
38
  end
39
39
  end
40
40
 
41
+ # Acts like self.[] (read only), except it keeps a cache of the fetch
42
+ # results in memory for the lifetime of the thread. Useful for applications
43
+ # like web apps which create a new thread for each HTTP request.
44
+ def self.cached_fetch( *args )
45
+ if args.size > 1
46
+ self[*args]
47
+ else
48
+ cache = Thread.current["m4dbi_cache_#{self.table}"] ||= Hash.new
49
+ cache[*args] ||= self[*args]
50
+ end
51
+ end
52
+
41
53
  def self.pk_clause
42
54
  pk.
43
55
  map { |col| "#{col} = ?" }.
data/lib/m4dbi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module M4DBI
2
- VERSION = '0.8.5'
2
+ VERSION = '0.8.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: m4dbi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-17 00:00:00.000000000 Z
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: metaid