cache-backend-iron-cache 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.rvmrc +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +9 -0
- data/cache-backend-iron-cache.gemspec +22 -0
- data/lib/cache-backend-iron-cache.rb +25 -0
- data/lib/cache-backend-iron-cache/version.rb +7 -0
- data/spec/cache_backend_iron_cache_spec.rb +39 -0
- data/spec/spec_helper.rb +11 -0
- metadata +92 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Thorben Schröder
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Cache::Backend::IronCache
|
2
|
+
|
3
|
+
An Iron Cache backend for the Quarter Spiral ``cache-client`` gem.
|
4
|
+
|
5
|
+
## Setup
|
6
|
+
|
7
|
+
Require this gem and the ``cache-client`` gem e.g. in your Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'cache-client'
|
11
|
+
gem 'cache-backend-iron-cache'
|
12
|
+
```
|
13
|
+
|
14
|
+
Then use it like this:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
cache_client = Cache::Client.new(Cache::Backend::IronCache, 'IRON_CACHE_PROJECT_ID', 'IRON_CACHE_TOKEN', 'CACHE_NAME', more_iron_cache_client_options)
|
18
|
+
```
|
19
|
+
``more_iron_cache_client_options`` is a hash and can be omitted. When set it will be directly sent to the [Iron Cache client](https://github.com/iron-io/iron_cache_ruby/blob/master/lib/iron_cache/client.rb)
|
20
|
+
|
21
|
+
## Testing
|
22
|
+
|
23
|
+
Tests need a connection to the internet and you must set two environment variables with your Iron Cache project id and token: ``TEST_IRON_CACHE_PROJECT_ID`` and ``TEST_IRON_CACHE_TOKEN``.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cache-backend-iron-cache/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "cache-backend-iron-cache"
|
8
|
+
gem.version = Cache::Backend::IronCache::VERSION
|
9
|
+
gem.authors = ["Thorben Schröder"]
|
10
|
+
gem.email = ["stillepost@gmail.com"]
|
11
|
+
gem.description = %q{An Iron Cache backend for the Quarter Spiral cache-client gem.}
|
12
|
+
gem.summary = %q{An Iron Cache backend for the Quarter Spiral cache-client gem.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'iron_cache', '1.4.0'
|
21
|
+
gem.add_dependency 'json', '~> 1.7.7'
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'iron_cache'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require "cache-backend-iron-cache/version"
|
5
|
+
|
6
|
+
module Cache
|
7
|
+
module Backend
|
8
|
+
class IronCache
|
9
|
+
def initialize(project_id, token, cache, options = {})
|
10
|
+
options = {project_id: project_id, token: token}.merge(options)
|
11
|
+
@client = ::IronCache::Client.new(options).cache(cache)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(key)
|
15
|
+
value = @client.get(key)
|
16
|
+
return unless value
|
17
|
+
JSON.parse(value.value)['value']
|
18
|
+
end
|
19
|
+
|
20
|
+
def set(key, value)
|
21
|
+
@client.put(key, JSON.dump({value: value}))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative './spec_helper'
|
2
|
+
|
3
|
+
describe Cache::Backend::IronCache do
|
4
|
+
before do
|
5
|
+
@ironcache = IronCache::Client.new(project_id: IRON_CACHE_PROJECT_ID, token: IRON_CACHE_TOKEN).cache("tests")
|
6
|
+
@client = Cache::Client.new(Cache::Backend::IronCache, IRON_CACHE_PROJECT_ID, IRON_CACHE_TOKEN, 'tests')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "works" do
|
10
|
+
begin
|
11
|
+
@ironcache.delete('a-key')
|
12
|
+
rescue Rest::HttpError
|
13
|
+
# that's ok
|
14
|
+
end
|
15
|
+
@client.get('a-key').must_be_nil
|
16
|
+
@client.set('a-key', 'some info')
|
17
|
+
@client.get('a-key').must_equal('some info')
|
18
|
+
|
19
|
+
@ironcache.get('a-key').value.must_equal(JSON.dump("value" => "some info"))
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can set keys to nil" do
|
23
|
+
@client.set('a-key', 'some info')
|
24
|
+
@client.get('a-key').wont_be_nil
|
25
|
+
@client.set('a-key', nil)
|
26
|
+
@client.get('a-key').must_be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "works with hashes" do
|
30
|
+
@client.set('a-key', '')
|
31
|
+
@client.set('a-key', {'bla' => 'blub', 'hallo' => 123.4})
|
32
|
+
@client.get('a-key').must_equal({'bla' => 'blub', 'hallo' => 123.4})
|
33
|
+
end
|
34
|
+
|
35
|
+
it "works with numbers" do
|
36
|
+
@client.set('a-key', 34.546)
|
37
|
+
@client.get('a-key').must_equal(34.546)
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Bundler.require
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
IRON_CACHE_PROJECT_ID = ENV['TEST_IRON_CACHE_PROJECT_ID']
|
6
|
+
IRON_CACHE_TOKEN = ENV['TEST_IRON_CACHE_TOKEN']
|
7
|
+
|
8
|
+
raise "Please set the TEST_IRON_CACHE_PROJECT_ID and TEST_IRON_CACHE_TOKEN environment variables in order to run the tests!" unless IRON_CACHE_PROJECT_ID && IRON_CACHE_TOKEN
|
9
|
+
|
10
|
+
require 'cache-client'
|
11
|
+
require 'cache-backend-iron-cache'
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cache-backend-iron-cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thorben Schröder
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: iron_cache
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.4.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.4.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.7.7
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.7.7
|
46
|
+
description: An Iron Cache backend for the Quarter Spiral cache-client gem.
|
47
|
+
email:
|
48
|
+
- stillepost@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .rvmrc
|
55
|
+
- CHANGELOG.md
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- cache-backend-iron-cache.gemspec
|
61
|
+
- lib/cache-backend-iron-cache.rb
|
62
|
+
- lib/cache-backend-iron-cache/version.rb
|
63
|
+
- spec/cache_backend_iron_cache_spec.rb
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
homepage: ''
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.24
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: An Iron Cache backend for the Quarter Spiral cache-client gem.
|
89
|
+
test_files:
|
90
|
+
- spec/cache_backend_iron_cache_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
has_rdoc:
|