evt-entity_cache 0.11.1.4 → 0.12.0.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 +1 -0
- data/lib/entity_cache/controls/record.rb +9 -2
- data/lib/entity_cache/controls/storage/persistent.rb +4 -2
- data/lib/entity_cache/controls/storage/temporary.rb +3 -1
- data/lib/entity_cache/controls/subject.rb +11 -0
- data/lib/entity_cache/controls/time.rb +7 -4
- data/lib/entity_cache/entity_cache.rb +10 -12
- data/lib/entity_cache/error.rb +3 -0
- data/lib/entity_cache/record.rb +5 -3
- data/lib/entity_cache/storage/temporary.rb +1 -1
- data/lib/entity_cache/storage/temporary/{factory.rb → build.rb} +1 -1
- data/lib/entity_cache/substitute.rb +2 -2
- metadata +6 -5
- data/lib/loader.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c13e158e958cbdf1b17b702403a04cab1e97b9e
|
4
|
+
data.tar.gz: c87287bf2c2dd8c6b4c8497f422e3d0de3dc04de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 376f814a1a462177be63978ad21dcb44a4c411982ec80a9f7272b2b7f19e38489a62930705840ffbfbe92445ed047943aa7984ae1adc12f4e83b0402dc194af3
|
7
|
+
data.tar.gz: b5e0b438bd336036fb33b4edf8a51781b92789bb84f7d9ebc11f69164247fe84cbd558ec99e053323e5c8cc2eee934b4eb7e153948627bfd4df21565c78e1cdd
|
data/lib/entity_cache.rb
CHANGED
@@ -6,6 +6,8 @@ require 'virtual'; Virtual.activate
|
|
6
6
|
|
7
7
|
require 'entity_cache/log'
|
8
8
|
|
9
|
+
require 'entity_cache/error'
|
10
|
+
|
9
11
|
require 'entity_cache/record'
|
10
12
|
|
11
13
|
require 'entity_cache/storage/persistent'
|
@@ -14,7 +16,7 @@ require 'entity_cache/storage/persistent/substitute'
|
|
14
16
|
require 'entity_cache/storage/persistent/telemetry'
|
15
17
|
|
16
18
|
require 'entity_cache/storage/temporary'
|
17
|
-
require 'entity_cache/storage/temporary/
|
19
|
+
require 'entity_cache/storage/temporary/build'
|
18
20
|
require 'entity_cache/storage/temporary/scope'
|
19
21
|
require 'entity_cache/storage/temporary/scope/exclusive'
|
20
22
|
require 'entity_cache/storage/temporary/scope/shared'
|
@@ -6,6 +6,7 @@ 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
|
+
require 'entity_cache/controls/subject'
|
9
10
|
require 'entity_cache/controls/time'
|
10
11
|
require 'entity_cache/controls/version'
|
11
12
|
require 'entity_cache/controls/persist_interval'
|
@@ -10,14 +10,21 @@ class EntityCache
|
|
10
10
|
time = Time.example
|
11
11
|
persisted_time = time
|
12
12
|
|
13
|
-
EntityCache::Record.new
|
13
|
+
EntityCache::Record.new(
|
14
|
+
id,
|
15
|
+
entity,
|
16
|
+
version,
|
17
|
+
time,
|
18
|
+
persisted_version,
|
19
|
+
persisted_time
|
20
|
+
)
|
14
21
|
end
|
15
22
|
|
16
23
|
module Persisted
|
17
24
|
def self.example(id=nil)
|
18
25
|
version = Version::Persistent.example
|
19
26
|
|
20
|
-
Record.example
|
27
|
+
Record.example(id, version: version)
|
21
28
|
end
|
22
29
|
end
|
23
30
|
end
|
@@ -27,11 +27,13 @@ class EntityCache
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.example
|
30
|
-
|
30
|
+
subject = Subject.example
|
31
|
+
|
32
|
+
Example.build(subject)
|
31
33
|
end
|
32
34
|
|
33
35
|
def self.substitute
|
34
|
-
SubstAttr::Substitute.build
|
36
|
+
SubstAttr::Substitute.build(Example)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -1,12 +1,15 @@
|
|
1
1
|
class EntityCache
|
2
2
|
module Controls
|
3
|
-
Time = Clock::Controls::Time
|
4
|
-
|
5
3
|
module Time
|
4
|
+
include Clock::Controls::Time
|
5
|
+
|
6
6
|
def self.example(time=nil, precision: nil)
|
7
|
-
time ||= Raw.example
|
8
7
|
precision ||= 5
|
9
|
-
|
8
|
+
|
9
|
+
Clock::Controls::Time.example(
|
10
|
+
time=nil,
|
11
|
+
precision: precision
|
12
|
+
)
|
10
13
|
end
|
11
14
|
end
|
12
15
|
end
|
@@ -1,6 +1,4 @@
|
|
1
1
|
class EntityCache
|
2
|
-
Error = Class.new(RuntimeError)
|
3
|
-
|
4
2
|
include Log::Dependency
|
5
3
|
|
6
4
|
configure :cache
|
@@ -11,7 +9,7 @@ class EntityCache
|
|
11
9
|
dependency :persistent_store, Storage::Persistent
|
12
10
|
dependency :temporary_store, Storage::Temporary
|
13
11
|
|
14
|
-
def self.build(subject, persistent_store: nil, persist_interval: nil, session: nil)
|
12
|
+
def self.build(subject, scope: nil, persistent_store: nil, persist_interval: nil, session: nil)
|
15
13
|
unless persistent_store.nil? == persist_interval.nil?
|
16
14
|
raise Error, "Must specify both the persistent store and persist interval, or neither"
|
17
15
|
end
|
@@ -22,7 +20,7 @@ class EntityCache
|
|
22
20
|
instance.persist_interval = persist_interval
|
23
21
|
|
24
22
|
Clock::UTC.configure instance
|
25
|
-
Storage::Temporary.configure
|
23
|
+
Storage::Temporary.configure(instance, subject, scope: scope)
|
26
24
|
|
27
25
|
persistent_store.configure(instance, subject, session: session)
|
28
26
|
|
@@ -48,18 +46,16 @@ class EntityCache
|
|
48
46
|
def put(id, entity, version, persisted_version=nil, persisted_time=nil, time: nil)
|
49
47
|
time ||= clock.iso8601(precision: 5)
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
record = Record.new id, entity, version, time, persisted_version, persisted_time
|
54
|
-
|
55
|
-
put_record record
|
49
|
+
record = Record.new(id, entity, version, time, persisted_version, persisted_time)
|
56
50
|
|
57
|
-
|
51
|
+
put_record(record)
|
58
52
|
|
59
53
|
record
|
60
54
|
end
|
61
55
|
|
62
56
|
def put_record(record)
|
57
|
+
logger.trace { "Writing cache (ID: #{record.id}, Entity Class: #{record.entity.class.name}, Version: #{record.version.inspect}, Time: #{record.time}, Persistent Version: #{record.persisted_version.inspect}, Persistent Time: #{record.persisted_time.inspect})" }
|
58
|
+
|
63
59
|
if persist_interval && record.versions_since_persisted >= persist_interval
|
64
60
|
persisted_time = clock.iso8601(precision: 5)
|
65
61
|
|
@@ -69,17 +65,19 @@ class EntityCache
|
|
69
65
|
record.persisted_time = persisted_time
|
70
66
|
end
|
71
67
|
|
68
|
+
logger.info { "Cache written (ID: #{record.id}, Entity Class: #{record.entity.class.name}, Version: #{record.version.inspect}, Time: #{record.time}, Persistent Version: #{record.persisted_version.inspect}, Persistent Time: #{record.persisted_time.inspect})" }
|
69
|
+
|
72
70
|
temporary_store.put record
|
73
71
|
end
|
74
72
|
|
75
73
|
def restore(id)
|
76
|
-
entity, persisted_version, persisted_time = persistent_store.get
|
74
|
+
entity, persisted_version, persisted_time = persistent_store.get(id)
|
77
75
|
|
78
76
|
return nil if entity.nil?
|
79
77
|
|
80
78
|
version = persisted_version
|
81
79
|
time = persisted_time
|
82
80
|
|
83
|
-
put
|
81
|
+
put(id, entity, version, persisted_version, persisted_time, time: time)
|
84
82
|
end
|
85
83
|
end
|
data/lib/entity_cache/record.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class EntityCache
|
2
|
-
class Record < Struct.new
|
2
|
+
class Record < Struct.new(:id, :entity, :version, :time, :persisted_version, :persisted_time)
|
3
3
|
def versions_since_persisted
|
4
4
|
persisted_version = self.persisted_version
|
5
5
|
persisted_version ||= -1
|
@@ -17,7 +17,9 @@ class EntityCache
|
|
17
17
|
includes.each do |attribute|
|
18
18
|
value = public_send attribute
|
19
19
|
|
20
|
-
|
20
|
+
if value.nil? && attribute == :version
|
21
|
+
value = NoStream.version
|
22
|
+
end
|
21
23
|
|
22
24
|
responses << value
|
23
25
|
end
|
@@ -32,7 +34,7 @@ class EntityCache
|
|
32
34
|
module NoStream
|
33
35
|
def self.destructure(includes=nil)
|
34
36
|
record = Record.new
|
35
|
-
record.destructure
|
37
|
+
record.destructure(includes)
|
36
38
|
end
|
37
39
|
|
38
40
|
def self.version
|
@@ -17,7 +17,7 @@ class EntityCache
|
|
17
17
|
def self.configure(receiver, subject, scope: nil, attr_name: nil)
|
18
18
|
attr_name ||= :temporary_store
|
19
19
|
|
20
|
-
instance =
|
20
|
+
instance = Build.(subject, scope: scope)
|
21
21
|
receiver.public_send "#{attr_name}=", instance
|
22
22
|
instance
|
23
23
|
end
|
@@ -17,9 +17,9 @@ class EntityCache
|
|
17
17
|
|
18
18
|
time = clock.iso8601(precision: 5)
|
19
19
|
|
20
|
-
record = Record.new
|
20
|
+
record = Record.new(id, entity, version, time, persisted_version, time)
|
21
21
|
|
22
|
-
temporary_store.put
|
22
|
+
temporary_store.put(record)
|
23
23
|
end
|
24
24
|
|
25
25
|
def put_record(record)
|
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.12.0.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: 2017-06-
|
11
|
+
date: 2017-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-configure
|
@@ -136,10 +136,12 @@ files:
|
|
136
136
|
- lib/entity_cache/controls/record.rb
|
137
137
|
- lib/entity_cache/controls/storage/persistent.rb
|
138
138
|
- lib/entity_cache/controls/storage/temporary.rb
|
139
|
+
- lib/entity_cache/controls/subject.rb
|
139
140
|
- lib/entity_cache/controls/time.rb
|
140
141
|
- lib/entity_cache/controls/version.rb
|
141
142
|
- lib/entity_cache/defaults.rb
|
142
143
|
- lib/entity_cache/entity_cache.rb
|
144
|
+
- lib/entity_cache/error.rb
|
143
145
|
- lib/entity_cache/log.rb
|
144
146
|
- lib/entity_cache/record.rb
|
145
147
|
- lib/entity_cache/storage/persistent.rb
|
@@ -147,12 +149,11 @@ files:
|
|
147
149
|
- lib/entity_cache/storage/persistent/substitute.rb
|
148
150
|
- lib/entity_cache/storage/persistent/telemetry.rb
|
149
151
|
- lib/entity_cache/storage/temporary.rb
|
150
|
-
- lib/entity_cache/storage/temporary/
|
152
|
+
- lib/entity_cache/storage/temporary/build.rb
|
151
153
|
- lib/entity_cache/storage/temporary/scope.rb
|
152
154
|
- lib/entity_cache/storage/temporary/scope/exclusive.rb
|
153
155
|
- lib/entity_cache/storage/temporary/scope/shared.rb
|
154
156
|
- lib/entity_cache/substitute.rb
|
155
|
-
- lib/loader.rb
|
156
157
|
homepage: https://github.com/eventide-project/entity-cache
|
157
158
|
licenses:
|
158
159
|
- MIT
|
@@ -165,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
166
|
requirements:
|
166
167
|
- - ">="
|
167
168
|
- !ruby/object:Gem::Version
|
168
|
-
version: 2.
|
169
|
+
version: 2.4.0
|
169
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
171
|
requirements:
|
171
172
|
- - ">="
|
data/lib/loader.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
lib/entity_cache.rb
|