coin 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.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Coin
2
2
 
3
- ## Memcached? We don't need no stinking Memcached.
3
+ ## Memcached? We don't need no stinking Memcached. <sup><a href="#cultural-references">1</a></sup>
4
4
 
5
- ... Well, you might depending upon your specific needs.
6
- But be sure to have a look at Coin before you reach for the sledgehammer.
5
+ Well... you might depending upon your specific needs.,
6
+ but have a look at Coin before you reach for the sledgehammer.
7
7
 
8
8
  Coin is an absurdly simple in memory object caching system written in Ruby.
9
9
 
@@ -104,6 +104,24 @@ Coin.start_server # => true
104
104
  Coin.start_server true # => true
105
105
  ```
106
106
 
107
+ ## Best Practices
108
+
109
+ All objects stored with Coin must be able to marshal.
110
+
111
+ Its generally a good idea to store only the most basic objects.
112
+ For example:
113
+
114
+ * Boolean
115
+ * String
116
+ * Number
117
+
118
+ Its possible to store more complex objects such as:
119
+
120
+ * Array
121
+ * Hash
122
+
123
+ Just be sure to limit the keys & values to basic types.
124
+
107
125
  ## Run the Tests
108
126
 
109
127
  ```bash
@@ -122,4 +140,7 @@ shared access across all processes on a **single machine**.
122
140
  _It should be relatively simple to update Coin to work across multiple machines,
123
141
  so keep an eye peeled for this feature in the future._
124
142
 
125
- ![Coin Processes](https://www.lucidchart.com/publicSegments/view/50b8299a-7c5c-4175-8121-6b190a7a0a70/image.png)
143
+
144
+ ## Cultural References
145
+
146
+ 1. "Badges? We don't need no stinking badges!" - from Mel Brooks' film [Blazing Saddles](http://en.wikipedia.org/wiki/Stinking_badges)
data/lib/coin/vault.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  require "thread"
2
2
  require "singleton"
3
3
  require "forwardable"
4
+ require "monitor"
4
5
 
5
6
  module Coin
6
7
  class Vault
7
8
  extend Forwardable
8
9
  include Singleton
10
+ include MonitorMixin
9
11
  def_delegators :@dict, :length
10
12
 
11
13
  def read(key)
@@ -17,7 +19,7 @@ module Coin
17
19
 
18
20
  def read_and_delete(key)
19
21
  value = nil
20
- @mutex.synchronize do
22
+ synchronize do
21
23
  value = read(key)
22
24
  @dict.delete(key)
23
25
  end
@@ -25,18 +27,18 @@ module Coin
25
27
  end
26
28
 
27
29
  def write(key, value, lifetime=300)
28
- @mutex.synchronize do
30
+ synchronize do
29
31
  @dict[key] = { :value => value, :cached_at => Time.now, :lifetime => lifetime }
30
32
  end
31
33
  value
32
34
  end
33
35
 
34
36
  def delete(key)
35
- @mutex.synchronize { @dict.delete(key) }
37
+ synchronize { @dict.delete(key) }
36
38
  end
37
39
 
38
40
  def clear
39
- @mutex.synchronize { @dict = {} }
41
+ synchronize { @dict = {} }
40
42
  end
41
43
 
42
44
  def ok?
@@ -46,9 +48,11 @@ module Coin
46
48
  protected
47
49
 
48
50
  def initialize
49
- @mutex = Mutex.new
50
51
  @dict = {}
51
52
  start_sweeper
53
+ # have to directly call mon_initialize since this is a
54
+ # singleton class and constructor is protected
55
+ mon_initialize
52
56
  end
53
57
 
54
58
  def start_sweeper
data/lib/coin/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Coin
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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-11-30 00:00:00.000000000 Z
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: