evt-entity_cache 0.6.1.1 → 0.11.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/entity_cache.rb +3 -1
- data/lib/entity_cache/controls.rb +2 -2
- data/lib/entity_cache/controls/{write_behind_delay.rb → persist_interval.rb} +1 -1
- data/lib/entity_cache/controls/time.rb +8 -0
- data/lib/entity_cache/controls/version.rb +1 -1
- data/lib/entity_cache/defaults.rb +0 -4
- data/lib/entity_cache/entity_cache.rb +21 -19
- data/lib/entity_cache/log.rb +9 -0
- data/lib/entity_cache/record.rb +5 -1
- data/lib/entity_cache/storage/persistent.rb +14 -13
- data/lib/entity_cache/storage/persistent/substitute.rb +1 -1
- data/lib/entity_cache/storage/temporary.rb +2 -3
- data/lib/entity_cache/storage/temporary/factory.rb +1 -1
- data/lib/entity_cache/substitute.rb +4 -4
- data/lib/loader.rb +1 -0
- metadata +23 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85ef1e5e7ba8f3a9032104108c26ff2a4faa4980
|
4
|
+
data.tar.gz: dccc3b8bac1e420ae3d9357a2838aa80acf8b263
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0155c692c01e6996933f05d490c629204a6c557948a6c93f47503711737b94facda5260a46e920ae57c3b533c6b1371d64ab4d8682c119330e1f03fed03dda57
|
7
|
+
data.tar.gz: db9faf371a1398e8cf5ecc3e672fa9a2d405d8c9051cdf30684f99922b6de8528656ad456c0c5f0fc17b48c0f30bb49097ab2a187fffa4928119e6219f9922c5
|
data/lib/entity_cache.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'configure'; Configure.activate
|
2
2
|
require 'settings'; Settings.activate
|
3
3
|
require 'telemetry'
|
4
|
-
require '
|
4
|
+
require 'log'
|
5
5
|
require 'virtual'; Virtual.activate
|
6
6
|
|
7
|
+
require 'entity_cache/log'
|
8
|
+
|
7
9
|
require 'entity_cache/record'
|
8
10
|
|
9
11
|
require 'entity_cache/storage/persistent'
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'clock/controls'
|
2
2
|
require 'identifier/uuid/controls'
|
3
3
|
|
4
|
-
require 'entity_cache/controls/entity'
|
5
4
|
require 'entity_cache/controls/id'
|
5
|
+
require 'entity_cache/controls/entity'
|
6
6
|
require 'entity_cache/controls/record'
|
7
7
|
require 'entity_cache/controls/storage/persistent'
|
8
8
|
require 'entity_cache/controls/storage/temporary'
|
9
9
|
require 'entity_cache/controls/time'
|
10
10
|
require 'entity_cache/controls/version'
|
11
|
-
require 'entity_cache/controls/
|
11
|
+
require 'entity_cache/controls/persist_interval'
|
@@ -1,65 +1,67 @@
|
|
1
1
|
class EntityCache
|
2
|
-
|
2
|
+
Error = Class.new(RuntimeError)
|
3
3
|
|
4
|
-
|
4
|
+
include Log::Dependency
|
5
|
+
|
6
|
+
configure :cache
|
7
|
+
|
8
|
+
attr_accessor :persist_interval
|
5
9
|
|
6
10
|
dependency :clock, Clock::UTC
|
7
|
-
dependency :logger, Telemetry::Logger
|
8
11
|
dependency :persistent_store, Storage::Persistent
|
9
12
|
dependency :temporary_store, Storage::Temporary
|
10
13
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
+
def self.build(subject, persistent_store: nil, persist_interval: nil, session: nil)
|
15
|
+
unless persistent_store.nil? == persist_interval.nil?
|
16
|
+
raise Error, "Must specify both the persistent store and persist interval, or neither"
|
17
|
+
end
|
14
18
|
|
15
|
-
def self.build(subject, persistent_store: nil, write_behind_delay: nil)
|
16
19
|
persistent_store ||= Defaults.persistent_store
|
17
|
-
write_behind_delay ||= Defaults.write_behind_delay
|
18
20
|
|
19
|
-
instance = new
|
21
|
+
instance = new
|
22
|
+
instance.persist_interval = persist_interval
|
20
23
|
|
21
24
|
Clock::UTC.configure instance
|
22
|
-
Telemetry::Logger.configure instance
|
23
25
|
Storage::Temporary.configure instance, subject
|
24
26
|
|
25
|
-
persistent_store.configure
|
27
|
+
persistent_store.configure(instance, subject, session: session)
|
26
28
|
|
27
29
|
instance
|
28
30
|
end
|
29
31
|
|
30
32
|
def get(id)
|
31
|
-
logger.
|
33
|
+
logger.trace { "Reading cache (ID: #{id.inspect})" }
|
32
34
|
|
33
35
|
record = temporary_store.get id
|
34
36
|
record ||= restore id
|
35
37
|
|
36
38
|
if record.nil?
|
37
|
-
logger.
|
39
|
+
logger.info { "Cache miss (ID: #{id.inspect})" }
|
38
40
|
return nil
|
39
41
|
end
|
40
42
|
|
41
|
-
logger.
|
43
|
+
logger.info { "Cache hit (ID: #{id.inspect}, Entity Class: #{record.entity.class.name}, Version: #{record.version.inspect}, Time: #{record.time})" }
|
42
44
|
|
43
45
|
record
|
44
46
|
end
|
45
47
|
|
46
48
|
def put(id, entity, version, persisted_version=nil, persisted_time=nil, time: nil)
|
47
|
-
time ||= clock.iso8601
|
49
|
+
time ||= clock.iso8601(precision: 5)
|
48
50
|
|
49
|
-
logger.
|
51
|
+
logger.trace { "Writing cache (ID: #{id}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time}, Persistent Version: #{persisted_version.inspect}, Persistent Time: #{persisted_time.inspect})" }
|
50
52
|
|
51
53
|
record = Record.new id, entity, version, time, persisted_version, persisted_time
|
52
54
|
|
53
55
|
put_record record
|
54
56
|
|
55
|
-
logger.
|
57
|
+
logger.info { "Cache written (ID: #{id}, Entity Class: #{record.entity.class.name}, Version: #{record.version.inspect}, Time: #{record.time}, Persistent Version: #{persisted_version.inspect}, Persistent Time: #{persisted_time.inspect})" }
|
56
58
|
|
57
59
|
record
|
58
60
|
end
|
59
61
|
|
60
62
|
def put_record(record)
|
61
|
-
if
|
62
|
-
persisted_time = clock.iso8601
|
63
|
+
if persist_interval && record.versions_since_persisted >= persist_interval
|
64
|
+
persisted_time = clock.iso8601(precision: 5)
|
63
65
|
|
64
66
|
persistent_store.put record.id, record.entity, record.version, persisted_time
|
65
67
|
|
data/lib/entity_cache/record.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class EntityCache
|
2
2
|
class Record < Struct.new :id, :entity, :version, :time, :persisted_version, :persisted_time
|
3
|
-
def
|
3
|
+
def versions_since_persisted
|
4
4
|
persisted_version = self.persisted_version
|
5
5
|
persisted_version ||= -1
|
6
6
|
|
@@ -25,6 +25,10 @@ class EntityCache
|
|
25
25
|
responses
|
26
26
|
end
|
27
27
|
|
28
|
+
def age_milliseconds
|
29
|
+
Clock::UTC.elapsed_milliseconds(time, Clock::UTC.now)
|
30
|
+
end
|
31
|
+
|
28
32
|
module NoStream
|
29
33
|
def self.destructure(includes=nil)
|
30
34
|
record = Record.new
|
@@ -1,13 +1,16 @@
|
|
1
1
|
class EntityCache
|
2
2
|
module Storage
|
3
3
|
module Persistent
|
4
|
+
Error = Class.new(RuntimeError)
|
5
|
+
|
4
6
|
extend Configure::Macro
|
5
7
|
|
6
8
|
def self.included(cls)
|
7
9
|
cls.class_exec do
|
10
|
+
include Log::Dependency
|
11
|
+
|
8
12
|
configure :persistent_store
|
9
13
|
|
10
|
-
dependency :logger, ::Telemetry::Logger
|
11
14
|
dependency :telemetry, ::Telemetry
|
12
15
|
|
13
16
|
extend Build
|
@@ -16,7 +19,7 @@ class EntityCache
|
|
16
19
|
prepend Get
|
17
20
|
prepend Put
|
18
21
|
|
19
|
-
virtual :
|
22
|
+
virtual :configure unless instance_methods.include?(:configure)
|
20
23
|
abstract :get unless instance_methods.include?(:get)
|
21
24
|
abstract :put unless instance_methods.include?(:put)
|
22
25
|
end
|
@@ -30,13 +33,13 @@ class EntityCache
|
|
30
33
|
|
31
34
|
module Get
|
32
35
|
def get(id)
|
33
|
-
logger.
|
36
|
+
logger.trace { "Getting entity (ID: #{id.inspect})" }
|
34
37
|
|
35
38
|
entity, version, time = super
|
36
39
|
|
37
40
|
telemetry.record :get, Telemetry::Data.new(id, entity, version, time)
|
38
41
|
|
39
|
-
logger.
|
42
|
+
logger.debug { "Got entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})" }
|
40
43
|
|
41
44
|
return entity, version, time
|
42
45
|
end
|
@@ -44,24 +47,24 @@ class EntityCache
|
|
44
47
|
|
45
48
|
module Put
|
46
49
|
def put(id, entity, version, time)
|
47
|
-
logger.
|
50
|
+
logger.trace { "Putting entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})" }
|
48
51
|
|
49
|
-
super
|
52
|
+
res = super
|
50
53
|
|
51
54
|
telemetry.record :put, Telemetry::Data.new(id, entity, version, time)
|
52
55
|
|
53
|
-
logger.
|
56
|
+
logger.debug { "Put entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})" }
|
54
57
|
|
55
|
-
|
58
|
+
res
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
59
62
|
module Build
|
60
|
-
def build(subject)
|
63
|
+
def build(subject, session: nil)
|
61
64
|
instance = new subject
|
62
|
-
|
65
|
+
|
63
66
|
::Telemetry.configure instance
|
64
|
-
instance.
|
67
|
+
instance.configure(session: session)
|
65
68
|
instance
|
66
69
|
end
|
67
70
|
end
|
@@ -73,8 +76,6 @@ class EntityCache
|
|
73
76
|
sink
|
74
77
|
end
|
75
78
|
end
|
76
|
-
|
77
|
-
Error = Class.new StandardError
|
78
79
|
end
|
79
80
|
end
|
80
81
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class EntityCache
|
2
2
|
module Storage
|
3
3
|
class Temporary
|
4
|
-
|
4
|
+
include Log::Dependency
|
5
5
|
|
6
|
-
|
6
|
+
attr_reader :subject
|
7
7
|
|
8
8
|
def initialize(subject)
|
9
9
|
@subject = subject
|
@@ -11,7 +11,6 @@ class EntityCache
|
|
11
11
|
|
12
12
|
def self.build(subject)
|
13
13
|
instance = new subject
|
14
|
-
Telemetry::Logger.configure instance
|
15
14
|
instance
|
16
15
|
end
|
17
16
|
|
@@ -5,17 +5,17 @@ class EntityCache
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class EntityCache < EntityCache
|
8
|
+
include Log::Dependency
|
9
|
+
|
8
10
|
def self.build
|
9
|
-
|
10
|
-
Telemetry::Logger.configure instance
|
11
|
-
instance
|
11
|
+
new
|
12
12
|
end
|
13
13
|
|
14
14
|
def add(id, entity, version=nil, persisted_version: nil)
|
15
15
|
version ||= 0
|
16
16
|
persisted_version ||= version
|
17
17
|
|
18
|
-
time = clock.iso8601
|
18
|
+
time = clock.iso8601(precision: 5)
|
19
19
|
|
20
20
|
record = Record.new id, entity, version, time, persisted_version, time
|
21
21
|
|
data/lib/loader.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
entity_cache.rb
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-entity_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-configure
|
@@ -67,7 +67,21 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: evt-telemetry
|
70
|
+
name: evt-telemetry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: evt-log
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
@@ -95,7 +109,7 @@ dependencies:
|
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: test_bench
|
112
|
+
name: ntl-test_bench
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - ">="
|
@@ -118,14 +132,15 @@ files:
|
|
118
132
|
- lib/entity_cache/controls.rb
|
119
133
|
- lib/entity_cache/controls/entity.rb
|
120
134
|
- lib/entity_cache/controls/id.rb
|
135
|
+
- lib/entity_cache/controls/persist_interval.rb
|
121
136
|
- lib/entity_cache/controls/record.rb
|
122
137
|
- lib/entity_cache/controls/storage/persistent.rb
|
123
138
|
- lib/entity_cache/controls/storage/temporary.rb
|
124
139
|
- lib/entity_cache/controls/time.rb
|
125
140
|
- lib/entity_cache/controls/version.rb
|
126
|
-
- lib/entity_cache/controls/write_behind_delay.rb
|
127
141
|
- lib/entity_cache/defaults.rb
|
128
142
|
- lib/entity_cache/entity_cache.rb
|
143
|
+
- lib/entity_cache/log.rb
|
129
144
|
- lib/entity_cache/record.rb
|
130
145
|
- lib/entity_cache/storage/persistent.rb
|
131
146
|
- lib/entity_cache/storage/persistent/none.rb
|
@@ -137,6 +152,7 @@ files:
|
|
137
152
|
- lib/entity_cache/storage/temporary/scope/exclusive.rb
|
138
153
|
- lib/entity_cache/storage/temporary/scope/shared.rb
|
139
154
|
- lib/entity_cache/substitute.rb
|
155
|
+
- lib/loader.rb
|
140
156
|
homepage: https://github.com/eventide-project/entity-cache
|
141
157
|
licenses:
|
142
158
|
- MIT
|
@@ -149,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
165
|
requirements:
|
150
166
|
- - ">="
|
151
167
|
- !ruby/object:Gem::Version
|
152
|
-
version: 2.
|
168
|
+
version: 2.3.3
|
153
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
170
|
requirements:
|
155
171
|
- - ">="
|
@@ -157,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
173
|
version: '0'
|
158
174
|
requirements: []
|
159
175
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.5.2
|
161
177
|
signing_key:
|
162
178
|
specification_version: 4
|
163
179
|
summary: Entity cache
|