dynamo-store 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +76 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Appraisals +21 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +809 -0
- data/LICENSE.txt +21 -0
- data/README.md +23 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dynamo-store.gemspec +52 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/active_support_5.0.gemfile +7 -0
- data/gemfiles/active_support_5.0.gemfile.lock +809 -0
- data/gemfiles/active_support_5.1.gemfile +7 -0
- data/gemfiles/active_support_5.1.gemfile.lock +809 -0
- data/gemfiles/active_support_5.2.gemfile +7 -0
- data/gemfiles/active_support_5.2.gemfile.lock +809 -0
- data/gemfiles/aws_sdk_2.gemfile +7 -0
- data/gemfiles/aws_sdk_2.gemfile.lock +113 -0
- data/gemfiles/aws_sdk_3.gemfile +7 -0
- data/gemfiles/aws_sdk_3.gemfile.lock +809 -0
- data/lib/active_support/cache/dynamo_store.rb +81 -0
- data/lib/dynamo-store/version.rb +5 -0
- data/lib/dynamo-store.rb +1 -0
- metadata +215 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/cache'
|
4
|
+
require 'active_support/notifications'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'aws-sdk-dynamodb'
|
8
|
+
rescue LoadError
|
9
|
+
require 'aws-sdk'
|
10
|
+
end
|
11
|
+
|
12
|
+
module ActiveSupport
|
13
|
+
module Cache
|
14
|
+
class Dynamo < Store
|
15
|
+
DEFAULT_HASH_KEY = 'CacheKey'
|
16
|
+
DEFAULT_TTL_KEY = 'TTL'
|
17
|
+
CONTENT_KEY = 'item_value'
|
18
|
+
|
19
|
+
attr_reader :data, :dynamodb_client, :hash_key, :ttl_key, :table_name
|
20
|
+
|
21
|
+
# Instantiate the store.
|
22
|
+
#
|
23
|
+
# Example:
|
24
|
+
# ActiveSupport::Cache::Dynamo.new(table_name: 'CacheTable')
|
25
|
+
# => hash_key: 'CacheKey', ttl_key: 'TTL', table_name: 'CacheTable'
|
26
|
+
#
|
27
|
+
# ActiveSupport::Cache::Dynamo.new(
|
28
|
+
# table_name: 'CacheTable',
|
29
|
+
# dynamo_client: client,
|
30
|
+
# hash_key: 'name',
|
31
|
+
# ttl_key: 'key_ttl'
|
32
|
+
# )
|
33
|
+
#
|
34
|
+
def initialize(
|
35
|
+
table_name:,
|
36
|
+
dynamo_client: nil,
|
37
|
+
hash_key: DEFAULT_HASH_KEY,
|
38
|
+
ttl_key: DEFAULT_TTL_KEY,
|
39
|
+
**opts
|
40
|
+
)
|
41
|
+
super(opts)
|
42
|
+
@table_name = table_name
|
43
|
+
@dynamodb_client = dynamo_client || Aws::DynamoDB::Client.new
|
44
|
+
@ttl_key = ttl_key
|
45
|
+
@hash_key = hash_key
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def read_entry(name, _options = nil)
|
51
|
+
result = dynamodb_client.get_item(
|
52
|
+
key: { hash_key => name },
|
53
|
+
table_name: table_name
|
54
|
+
)
|
55
|
+
|
56
|
+
return if result.item.nil?
|
57
|
+
|
58
|
+
Marshal.load(result.item[CONTENT_KEY]) # rubocop:disable Security/MarshalLoad
|
59
|
+
rescue TypeError
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def write_entry(name, value, _options = nil)
|
64
|
+
item = { hash_key => name, CONTENT_KEY => Marshal.dump(value) }
|
65
|
+
|
66
|
+
item[ttl_key] = value.expires_at.to_i if value.expires_at
|
67
|
+
|
68
|
+
dynamodb_client.put_item(item: item, table_name: table_name)
|
69
|
+
|
70
|
+
true
|
71
|
+
end
|
72
|
+
|
73
|
+
def delete_entry(name, _options)
|
74
|
+
dynamodb_client.delete_item(
|
75
|
+
key: { hash_key => name },
|
76
|
+
table_name: table_name
|
77
|
+
)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/dynamo-store.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'active_support/cache/dynamo_store'
|
metadata
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dynamo-store
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Harkness
|
8
|
+
- Brian Malinconico
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-04-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '5.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '5.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: aws-sdk
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '2.0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '2.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: appraisal
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: deep-cover
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rake
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '10.0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '10.0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rspec
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '3.0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '3.0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: simplecov
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: timecop
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: rspec_junit_formatter
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
description: ActiveSupport Cache Store for DynamoDb
|
155
|
+
email:
|
156
|
+
- david.harkness@terminus.com
|
157
|
+
- brian.malinconico@terminus.com
|
158
|
+
executables: []
|
159
|
+
extensions: []
|
160
|
+
extra_rdoc_files: []
|
161
|
+
files:
|
162
|
+
- ".circleci/config.yml"
|
163
|
+
- ".gitignore"
|
164
|
+
- ".rspec"
|
165
|
+
- ".travis.yml"
|
166
|
+
- Appraisals
|
167
|
+
- Gemfile
|
168
|
+
- Gemfile.lock
|
169
|
+
- LICENSE.txt
|
170
|
+
- README.md
|
171
|
+
- Rakefile
|
172
|
+
- bin/console
|
173
|
+
- bin/setup
|
174
|
+
- dynamo-store.gemspec
|
175
|
+
- gemfiles/.bundle/config
|
176
|
+
- gemfiles/active_support_5.0.gemfile
|
177
|
+
- gemfiles/active_support_5.0.gemfile.lock
|
178
|
+
- gemfiles/active_support_5.1.gemfile
|
179
|
+
- gemfiles/active_support_5.1.gemfile.lock
|
180
|
+
- gemfiles/active_support_5.2.gemfile
|
181
|
+
- gemfiles/active_support_5.2.gemfile.lock
|
182
|
+
- gemfiles/aws_sdk_2.gemfile
|
183
|
+
- gemfiles/aws_sdk_2.gemfile.lock
|
184
|
+
- gemfiles/aws_sdk_3.gemfile
|
185
|
+
- gemfiles/aws_sdk_3.gemfile.lock
|
186
|
+
- lib/active_support/cache/dynamo_store.rb
|
187
|
+
- lib/dynamo-store.rb
|
188
|
+
- lib/dynamo-store/version.rb
|
189
|
+
homepage: https://github.com/GetTerminus/dynamo-store
|
190
|
+
licenses:
|
191
|
+
- MIT
|
192
|
+
metadata:
|
193
|
+
homepage_uri: https://github.com/GetTerminus/dynamo-store
|
194
|
+
source_code_uri: https://github.com/GetTerminus/dynamo-cache-store.git
|
195
|
+
post_install_message:
|
196
|
+
rdoc_options: []
|
197
|
+
require_paths:
|
198
|
+
- lib
|
199
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
requirements: []
|
210
|
+
rubyforge_project:
|
211
|
+
rubygems_version: 2.7.3
|
212
|
+
signing_key:
|
213
|
+
specification_version: 4
|
214
|
+
summary: ActiveSupport Cache Store for DynamoDb
|
215
|
+
test_files: []
|