iron_cache 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iron_cache (0.1.0)
5
- iron_core (>= 0.1.4)
4
+ iron_cache (1.0.0)
5
+ iron_core (>= 0.2.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  ffi (1.0.11)
11
- iron_core (0.1.4)
12
- bundler (> 1.0.0)
13
- rest
14
- rest-client
11
+ iron_core (0.2.0)
12
+ rest (>= 2.0.0)
15
13
  memcache-client (1.8.5)
16
14
  mime-types (1.19)
15
+ net-http-persistent (2.7)
17
16
  rake (0.9.2.2)
18
- rest (1.0.0)
17
+ rest (2.0.0)
18
+ net-http-persistent
19
19
  rest-client (>= 0.3.0)
20
20
  rest-client (1.6.7)
21
21
  mime-types (>= 1.16)
22
- test-unit (2.5.0)
22
+ test-unit (2.5.1)
23
23
  typhoeus (0.4.2)
24
24
  ffi (~> 1.0)
25
25
  mime-types (~> 1.18)
data/README.md CHANGED
@@ -17,7 +17,7 @@ Getting Started
17
17
  The Basics
18
18
  =========
19
19
 
20
- **Get a cache object**
20
+ **Get a Cache object**
21
21
 
22
22
  You can have as many caches as you want, each with their own unique set of items.
23
23
 
@@ -27,13 +27,13 @@ Now you can use it:
27
27
 
28
28
  **Put** an item in the cache:
29
29
 
30
- msg = @cache.put("mykey", "hello world!")
31
- p msg
30
+ item = @cache.put("mykey", "hello world!")
31
+ p item
32
32
 
33
33
  **Get** an item from the cache:
34
34
 
35
- msg = @cache.get("mykey")
36
- p msg
35
+ item = @cache.get("mykey")
36
+ p item.value
37
37
 
38
38
  **Delete** an item from the cache:
39
39
 
data/iron_cache.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
16
16
 
17
17
  gem.required_rubygems_version = ">= 1.3.6"
18
18
  gem.required_ruby_version = Gem::Requirement.new(">= 1.9")
19
- gem.add_runtime_dependency "iron_core", ">= 0.1.4"
19
+ gem.add_runtime_dependency "iron_core", ">= 0.2.0"
20
20
 
21
21
  gem.add_development_dependency "test-unit"
22
22
  gem.add_development_dependency "rake"
@@ -9,29 +9,34 @@ module IronCache
9
9
 
10
10
  AWS_US_EAST_HOST = "cache-aws-us-east-1.iron.io"
11
11
 
12
- attr_accessor :cache_name, :logger
12
+ attr_accessor :logger
13
13
 
14
14
  def initialize(options={})
15
- super("cache", options)
15
+ default_options = {
16
+ :scheme => 'https',
17
+ :host => IronCache::Client::AWS_US_EAST_HOST,
18
+ :port => 443,
19
+ :api_version => 1,
20
+ :user_agent => 'iron_mq_ruby-' + IronCache::VERSION + ' (iron_core_ruby-' + IronCore.version + ')',
21
+ :cache_name => 'default'
22
+ }
16
23
 
17
- @logger = Logger.new(STDOUT)
18
- @logger.level = Logger::INFO
24
+ super('iron', 'cache', options, default_options, [:project_id, :token, :api_version, :cache_name])
19
25
 
20
- @cache_name = options[:cache_name] || options['cache_name'] || "default"
26
+ IronCore::Logger.error 'IronCache', "Token is not set", IronCore::Error if @token.nil?
21
27
 
22
- load_from_hash('defaults', {
23
- :scheme => 'https',
24
- :host => AWS_US_EAST_HOST,
25
- :port => 443,
26
- :api_version => 1,
27
- :user_agent => 'iron_cache_ruby-' + IronCache::VERSION + ' (iron_core_ruby-' + IronCore.version + ')'})
28
+ check_id(@project_id, 'project_id')
28
29
 
29
- if (not @token) || (not @project_id)
30
- IronCore::Logger.error 'IronCache', 'Both token and project_id must be specified'
31
- raise IronCore::IronError.new('Both token and project_id must be specified')
32
- end
30
+ @logger = Logger.new(STDOUT)
31
+ @logger.level = Logger::INFO
32
+ end
33
33
 
34
+ def headers
35
+ super.merge({'Authorization' => "OAuth #{@token}"})
36
+ end
34
37
 
38
+ def url
39
+ super + @api_version.to_s + '/'
35
40
  end
36
41
 
37
42
  def items
@@ -45,7 +50,6 @@ module IronCache
45
50
  def caches
46
51
  return Caches.new(self)
47
52
  end
48
-
49
53
  end
50
54
 
51
55
  class Error < StandardError
@@ -22,7 +22,7 @@ module IronCache
22
22
  @client.logger.debug "GET response: " + res.inspect
23
23
  json = @client.parse_response(res, true)
24
24
  return Item.new(self, json)
25
- rescue IronCore::IronResponseError => ex
25
+ rescue Rest::HttpError => ex
26
26
  @client.logger.debug ex.inspect
27
27
  if ex.code == 404
28
28
  return nil
@@ -108,4 +108,4 @@ module IronCache
108
108
  end
109
109
  end
110
110
 
111
- end
111
+ end
@@ -1,3 +1,3 @@
1
1
  module IronCache
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/iron_cache.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'rest'
1
2
  require_relative "iron_cache/version"
2
3
  require_relative 'iron_cache/caches'
3
4
  require_relative 'iron_cache/items'
data/test/test_base.rb CHANGED
@@ -33,4 +33,13 @@ class TestBase < Test::Unit::TestCase
33
33
  #puts 'cleared.'
34
34
  end
35
35
 
36
+ def assert_performance(time)
37
+ start_time = Time.now
38
+ yield
39
+ execution_time = Time.now - start_time
40
+ assert execution_time < time, "Execution time too big #{execution_time.round(2)}, should be #{time}"
41
+ end
42
+
43
+
44
+
36
45
  end
@@ -10,13 +10,18 @@ class IronCacheTests < TestBase
10
10
  end
11
11
  def test_performance_put_message
12
12
  @client.cache_name = 'test_basics'
13
- res = @client.items.put("key", "value")
13
+ assert_performance 0.02 do
14
+ @client.items.put("key", "value")
15
+ end
14
16
  end
15
17
 
16
18
  def test_performance_put_100_messages
17
19
  @client.cache_name = 'test_basics'
18
- 100.times do
19
- res = @client.items.put("key", "value")
20
+ assert_performance 2 do
21
+ 100.times do
22
+ res = @client.items.put("key", "value")
23
+ puts "putting message #{res.inspect}"
24
+ end
20
25
  end
21
26
  end
22
27
 
@@ -29,6 +29,12 @@ class IronCacheMemcachedTests < TestBase
29
29
  assert !ret.nil?
30
30
  assert ret == v
31
31
 
32
+ @memcache.delete(k)
33
+
34
+ ret = @memcache.get(k)
35
+ puts 'after delete: ' + ret.inspect
36
+ assert ret.nil?
37
+
32
38
  end
33
39
 
34
40
  def test_expiry_memcached
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
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-06-25 00:00:00.000000000 Z
12
+ date: 2012-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iron_core
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.1.4
21
+ version: 0.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.1.4
29
+ version: 0.2.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: test-unit
32
32
  requirement: !ruby/object:Gem::Requirement