neuron-client 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,6 +24,10 @@ Connect to the Membase (or Memcached) Server for limited read access to some exp
24
24
  Neuron::Client::API.default_api.configure do |config|
25
25
  config.connection_type = :membase
26
26
  config.membase_servers = "127.0.0.1:11211"
27
+ config.local_cache_ttl = 15.minutes
28
+ config.local_cache_soft_ttl = 1.minute
29
+ config.local_cache_retry_delay = 1.second
30
+ config.local_cache_max_items = 10_000
27
31
  end
28
32
 
29
33
  Short form to copy and paste into console:
@@ -38,7 +38,9 @@ module Neuron
38
38
 
39
39
  def inclusion(obj, attrib, valid_values)
40
40
  val = obj.send(attrib)
41
- raise "Inclusion: #{attrib} must be one of #{valid_values.join(', ')}" if !valid_values.include?(val)
41
+ if !valid_values.include?(val)
42
+ raise "Inclusion: #{attrib} must be one of #{valid_values.join(', ')}"
43
+ end
42
44
  end
43
45
 
44
46
  def configure_admin_connection
@@ -49,14 +51,16 @@ module Neuron
49
51
  rescue
50
52
  raise "Invalid admin_url: #{config.admin_url}"
51
53
  end
52
- self.connection = AdminConnection.new(config.admin_url, config.admin_key)
54
+ self.connection = AdminConnection.new(config.admin_url,config.admin_key)
53
55
  end
54
56
 
55
57
  def configure_membase_connection
56
58
  required(@config, :membase_servers)
57
59
  self.connection = MembaseConnection.new(config.membase_servers,
58
- :local_cache_size => config.local_cache_size,
59
- :local_cache_expires => config.local_cache_expires
60
+ :local_cache_ttl => config.local_cache_ttl,
61
+ :local_cache_soft_ttl => config.local_cache_soft_ttl,
62
+ :local_cache_retry_delay => config.local_cache_retry_delay,
63
+ :local_cache_max_items => config.local_cache_max_items
60
64
  )
61
65
  end
62
66
 
@@ -9,19 +9,37 @@ module Neuron
9
9
 
10
10
  def initialize(servers, opts={})
11
11
  @client = Dalli::Client.new(servers)
12
+ max_items = opts[:local_cache_max_items] || 10_000
13
+ ttl = opts[:local_cache_ttl] || 15.minutes
14
+ soft_ttl = [opts[:local_cache_soft_ttl] || 1.minute, ttl].min
15
+ retry_delay = [opts[:local_cache_retry_delay] || 1.second, soft_ttl].min
12
16
  @local_cache = LRUCache.new(
13
- :max_items => opts[:local_cache_size],
14
- :ttl => opts[:local_cache_expires] || 60.seconds)
17
+ :max_items => max_items,
18
+ :ttl => ttl,
19
+ :soft_ttl => soft_ttl,
20
+ :retry_delay => retry_delay)
15
21
  end
16
22
 
17
23
  def get(key, ttl=nil)
18
- @local_cache.fetch(key, local_ttl(ttl)) do
24
+ ttl = local_ttl(ttl)
25
+ soft_ttl =[@local_cache.soft_ttl, ttl].compact.min
26
+ retry_delay = [@local_cache.retry_delay, soft_ttl].compact.min
27
+ @local_cache.fetch(key,
28
+ :ttl => ttl,
29
+ :soft_ttl => soft_ttl,
30
+ :retry_delay => retry_delay) do
19
31
  @client.get(key)
20
32
  end
21
33
  end
22
34
 
23
35
  def fetch(key, ttl=nil, options=nil, &callback)
24
- @local_cache.fetch(key, local_ttl(ttl)) do
36
+ ttl = local_ttl(ttl)
37
+ soft_ttl =[@local_cache.soft_ttl, ttl].compact.min
38
+ retry_delay = [@local_cache.retry_delay, soft_ttl].compact.min
39
+ @local_cache.fetch(key,
40
+ :ttl => ttl,
41
+ :soft_ttl => soft_ttl,
42
+ :retry_delay => retry_delay) do
25
43
  @client.fetch(key, ttl, options, &callback)
26
44
  end
27
45
  end
@@ -1,5 +1,5 @@
1
1
  module Neuron
2
2
  module Client
3
- VERSION = "0.4.8"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency "tzinfo", "~> 0.3.29"
24
24
  s.add_dependency "i18n", ">= 0.5.0", "< 0.7"
25
25
  s.add_dependency "dalli", ">= 1.0.5", "< 1.2"
26
- s.add_dependency "lrucache", "~> 0.1.0"
26
+ s.add_dependency "lrucache", "~> 0.1.2"
27
27
  s.add_dependency "map", ">= 4.2.0", "< 5"
28
28
  s.add_dependency "deep_merge", "~> 1.0.0"
29
29
  s.add_dependency "json-schema", ">= 0.9.12", "< 1.1"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neuron-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 8
10
- version: 0.4.8
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - RMM Online
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-30 00:00:00 Z
18
+ date: 2012-04-03 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client
@@ -149,12 +149,12 @@ dependencies:
149
149
  requirements:
150
150
  - - ~>
151
151
  - !ruby/object:Gem::Version
152
- hash: 27
152
+ hash: 31
153
153
  segments:
154
154
  - 0
155
155
  - 1
156
- - 0
157
- version: 0.1.0
156
+ - 2
157
+ version: 0.1.2
158
158
  type: :runtime
159
159
  version_requirements: *id007
160
160
  - !ruby/object:Gem::Dependency