evt-entity_cache 0.13.0.0 → 0.14.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/entity_cache.rb +17 -15
  3. data/lib/entity_cache/controls.rb +12 -3
  4. data/lib/entity_cache/controls/entity.rb +27 -1
  5. data/lib/entity_cache/controls/persist_interval.rb +2 -22
  6. data/lib/entity_cache/controls/record.rb +33 -12
  7. data/lib/entity_cache/controls/storage/persistent.rb +8 -26
  8. data/lib/entity_cache/controls/storage/persistent/example.rb +41 -0
  9. data/lib/entity_cache/controls/storage/persistent/not_implemented.rb +19 -0
  10. data/lib/entity_cache/controls/storage/persistent/write.rb +25 -0
  11. data/lib/entity_cache/controls/storage/temporary.rb +14 -2
  12. data/lib/entity_cache/controls/subject.rb +2 -4
  13. data/lib/entity_cache/controls/time.rb +1 -12
  14. data/lib/entity_cache/controls/version.rb +5 -11
  15. data/lib/entity_cache/defaults.rb +2 -2
  16. data/lib/entity_cache/record.rb +36 -30
  17. data/lib/entity_cache/record/destructure.rb +29 -0
  18. data/lib/entity_cache/record/log_text.rb +9 -0
  19. data/lib/entity_cache/record/transformer.rb +26 -0
  20. data/lib/entity_cache/store/persistent/null.rb +15 -0
  21. data/lib/entity_cache/store/persistent/substitute.rb +64 -0
  22. data/lib/entity_cache/store/persistent/telemetry.rb +16 -0
  23. data/lib/entity_cache/store/temporary.rb +47 -0
  24. data/lib/entity_cache/store/temporary/build.rb +48 -0
  25. data/lib/entity_cache/store/temporary/build/defaults.rb +28 -0
  26. data/lib/entity_cache/{storage → store}/temporary/scope/exclusive.rb +1 -1
  27. data/lib/entity_cache/store/temporary/scope/global.rb +34 -0
  28. data/lib/entity_cache/store/temporary/scope/thread.rb +35 -0
  29. data/lib/entity_cache/store/temporary/substitute.rb +36 -0
  30. data/lib/entity_cache/substitute.rb +33 -17
  31. metadata +20 -58
  32. data/lib/entity_cache/entity_cache.rb +0 -83
  33. data/lib/entity_cache/error.rb +0 -3
  34. data/lib/entity_cache/storage/persistent.rb +0 -81
  35. data/lib/entity_cache/storage/persistent/none.rb +0 -15
  36. data/lib/entity_cache/storage/persistent/substitute.rb +0 -51
  37. data/lib/entity_cache/storage/persistent/telemetry.rb +0 -38
  38. data/lib/entity_cache/storage/temporary.rb +0 -56
  39. data/lib/entity_cache/storage/temporary/build.rb +0 -42
  40. data/lib/entity_cache/storage/temporary/scope/defaults.rb +0 -32
  41. data/lib/entity_cache/storage/temporary/scope/error.rb +0 -9
  42. data/lib/entity_cache/storage/temporary/scope/shared.rb +0 -31
@@ -0,0 +1,36 @@
1
+ class EntityCache
2
+ module Store
3
+ class Temporary
4
+ module Substitute
5
+ def self.build
6
+ Temporary.new
7
+ end
8
+
9
+ class Temporary < Scope::Exclusive
10
+ def add(id, entity, version, time, persisted_version: nil, persisted_time: nil)
11
+ record = Record.build(
12
+ id,
13
+ entity,
14
+ version,
15
+ time,
16
+ persisted_version: persisted_version,
17
+ persisted_time: persisted_time
18
+ )
19
+
20
+ put(record)
21
+ end
22
+
23
+ def put?(record=nil)
24
+ if record.nil?
25
+ records.any?
26
+ else
27
+ records.any? do |_, r|
28
+ r == record
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -5,40 +5,56 @@ class EntityCache
5
5
  end
6
6
 
7
7
  class EntityCache < EntityCache
8
- include Log::Dependency
9
-
10
8
  def self.build
11
9
  new
12
10
  end
13
11
 
14
- def add(id, entity, version=nil, persisted_version: nil)
12
+ def add(id, entity, version=nil, time: nil, persisted_version: nil, persisted_time: nil)
15
13
  version ||= 0
16
14
  persisted_version ||= version
17
-
18
- time = clock.iso8601(precision: 5)
19
-
20
- record = Record.new(id, entity, version, time, persisted_version, time)
15
+ time ||= clock.now
16
+ persisted_time ||= time
17
+
18
+ record = Record.build(
19
+ id,
20
+ entity,
21
+ version,
22
+ time,
23
+ persisted_version: persisted_version,
24
+ persisted_time: persisted_time
25
+ )
21
26
 
22
27
  temporary_store.put(record)
23
28
  end
24
29
 
25
- def put_record(record)
30
+ def put(id, entity, version, time: nil, persisted_version: nil, persisted_time: nil)
31
+ time ||= clock.now
32
+
33
+ record = Record.build(
34
+ id,
35
+ entity,
36
+ version,
37
+ time,
38
+ persisted_version: persisted_version,
39
+ persisted_time: persisted_time
40
+ )
41
+
26
42
  put_records << record
27
- end
28
43
 
29
- def put_records
30
- @put_records ||= []
44
+ record
31
45
  end
32
46
 
33
- module Assertions
34
- def put?(&blk)
35
- return put_records.any? if blk.nil?
47
+ def put?(&blk)
48
+ return put_records.any? if blk.nil?
36
49
 
37
- put_records.any? do |record|
38
- blk.(record)
39
- end
50
+ put_records.any? do |record|
51
+ blk.(record)
40
52
  end
41
53
  end
54
+
55
+ def put_records
56
+ @put_records ||= []
57
+ end
42
58
  end
43
59
  end
44
60
  end
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.13.0.0
4
+ version: 0.14.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-25 00:00:00.000000000 Z
11
+ date: 2017-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-configure
@@ -25,21 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: evt-clock
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: evt-identifier-uuid
28
+ name: evt-message_store
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
@@ -80,34 +66,6 @@ dependencies:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: evt-log
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: evt-virtual
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
69
  - !ruby/object:Gem::Dependency
112
70
  name: test_bench
113
71
  requirement: !ruby/object:Gem::Requirement
@@ -135,25 +93,29 @@ files:
135
93
  - lib/entity_cache/controls/persist_interval.rb
136
94
  - lib/entity_cache/controls/record.rb
137
95
  - lib/entity_cache/controls/storage/persistent.rb
96
+ - lib/entity_cache/controls/storage/persistent/example.rb
97
+ - lib/entity_cache/controls/storage/persistent/not_implemented.rb
98
+ - lib/entity_cache/controls/storage/persistent/write.rb
138
99
  - lib/entity_cache/controls/storage/temporary.rb
139
100
  - lib/entity_cache/controls/subject.rb
140
101
  - lib/entity_cache/controls/time.rb
141
102
  - lib/entity_cache/controls/version.rb
142
103
  - lib/entity_cache/defaults.rb
143
- - lib/entity_cache/entity_cache.rb
144
- - lib/entity_cache/error.rb
145
104
  - lib/entity_cache/log.rb
146
105
  - lib/entity_cache/record.rb
147
- - lib/entity_cache/storage/persistent.rb
148
- - lib/entity_cache/storage/persistent/none.rb
149
- - lib/entity_cache/storage/persistent/substitute.rb
150
- - lib/entity_cache/storage/persistent/telemetry.rb
151
- - lib/entity_cache/storage/temporary.rb
152
- - lib/entity_cache/storage/temporary/build.rb
153
- - lib/entity_cache/storage/temporary/scope/defaults.rb
154
- - lib/entity_cache/storage/temporary/scope/error.rb
155
- - lib/entity_cache/storage/temporary/scope/exclusive.rb
156
- - lib/entity_cache/storage/temporary/scope/shared.rb
106
+ - lib/entity_cache/record/destructure.rb
107
+ - lib/entity_cache/record/log_text.rb
108
+ - lib/entity_cache/record/transformer.rb
109
+ - lib/entity_cache/store/persistent/null.rb
110
+ - lib/entity_cache/store/persistent/substitute.rb
111
+ - lib/entity_cache/store/persistent/telemetry.rb
112
+ - lib/entity_cache/store/temporary.rb
113
+ - lib/entity_cache/store/temporary/build.rb
114
+ - lib/entity_cache/store/temporary/build/defaults.rb
115
+ - lib/entity_cache/store/temporary/scope/exclusive.rb
116
+ - lib/entity_cache/store/temporary/scope/global.rb
117
+ - lib/entity_cache/store/temporary/scope/thread.rb
118
+ - lib/entity_cache/store/temporary/substitute.rb
157
119
  - lib/entity_cache/substitute.rb
158
120
  homepage: https://github.com/eventide-project/entity-cache
159
121
  licenses:
@@ -167,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
129
  requirements:
168
130
  - - ">="
169
131
  - !ruby/object:Gem::Version
170
- version: 2.4.0
132
+ version: '2.4'
171
133
  required_rubygems_version: !ruby/object:Gem::Requirement
172
134
  requirements:
173
135
  - - ">="
@@ -1,83 +0,0 @@
1
- class EntityCache
2
- include Log::Dependency
3
-
4
- configure :cache
5
-
6
- attr_accessor :persist_interval
7
-
8
- dependency :clock, Clock::UTC
9
- dependency :persistent_store, Storage::Persistent
10
- dependency :temporary_store, Storage::Temporary
11
-
12
- def self.build(subject, scope: nil, persistent_store: nil, persist_interval: nil, session: nil)
13
- unless persistent_store.nil? == persist_interval.nil?
14
- raise Error, "Must specify both the persistent store and persist interval, or neither"
15
- end
16
-
17
- persistent_store ||= Defaults.persistent_store
18
-
19
- instance = new
20
- instance.persist_interval = persist_interval
21
-
22
- Clock::UTC.configure instance
23
- Storage::Temporary.configure(instance, subject, scope: scope)
24
-
25
- persistent_store.configure(instance, subject, session: session)
26
-
27
- instance
28
- end
29
-
30
- def get(id)
31
- logger.trace { "Reading cache (ID: #{id.inspect})" }
32
-
33
- record = temporary_store.get id
34
- record ||= restore id
35
-
36
- if record.nil?
37
- logger.info { "Cache miss (ID: #{id.inspect})" }
38
- return nil
39
- end
40
-
41
- logger.info { "Cache hit (ID: #{id.inspect}, Entity Class: #{record.entity.class.name}, Version: #{record.version.inspect}, Time: #{record.time})" }
42
-
43
- record
44
- end
45
-
46
- def put(id, entity, version, persisted_version=nil, persisted_time=nil, time: nil)
47
- time ||= clock.iso8601(precision: 5)
48
-
49
- record = Record.new(id, entity, version, time, persisted_version, persisted_time)
50
-
51
- put_record(record)
52
-
53
- record
54
- end
55
-
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
-
59
- if persist_interval && record.versions_since_persisted >= persist_interval
60
- persisted_time = clock.iso8601(precision: 5)
61
-
62
- persistent_store.put record.id, record.entity, record.version, persisted_time
63
-
64
- record.persisted_version = record.version
65
- record.persisted_time = persisted_time
66
- end
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
-
70
- temporary_store.put record
71
- end
72
-
73
- def restore(id)
74
- entity, persisted_version, persisted_time = persistent_store.get(id)
75
-
76
- return nil if entity.nil?
77
-
78
- version = persisted_version
79
- time = persisted_time
80
-
81
- put(id, entity, version, persisted_version, persisted_time, time: time)
82
- end
83
- end
@@ -1,3 +0,0 @@
1
- class EntityCache
2
- Error = Class.new(RuntimeError)
3
- end
@@ -1,81 +0,0 @@
1
- class EntityCache
2
- module Storage
3
- module Persistent
4
- Error = Class.new(RuntimeError)
5
-
6
- extend Configure::Macro
7
-
8
- def self.included(cls)
9
- cls.class_exec do
10
- include Log::Dependency
11
-
12
- configure :persistent_store
13
-
14
- dependency :telemetry, ::Telemetry
15
-
16
- extend Build
17
- extend RegisterTelemetrySink
18
-
19
- prepend Get
20
- prepend Put
21
-
22
- virtual :configure unless instance_methods.include?(:configure)
23
- abstract :get unless instance_methods.include?(:get)
24
- abstract :put unless instance_methods.include?(:put)
25
- end
26
- end
27
-
28
- attr_reader :subject
29
-
30
- def initialize(subject)
31
- @subject = subject
32
- end
33
-
34
- module Get
35
- def get(id)
36
- logger.trace { "Getting entity (ID: #{id.inspect})" }
37
-
38
- entity, version, time = super
39
-
40
- telemetry.record :get, Telemetry::Data.new(id, entity, version, time)
41
-
42
- logger.debug { "Got entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})" }
43
-
44
- return entity, version, time
45
- end
46
- end
47
-
48
- module Put
49
- def put(id, entity, version, time)
50
- logger.trace { "Putting entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})" }
51
-
52
- res = super
53
-
54
- telemetry.record :put, Telemetry::Data.new(id, entity, version, time)
55
-
56
- logger.debug { "Put entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})" }
57
-
58
- res
59
- end
60
- end
61
-
62
- module Build
63
- def build(subject, session: nil)
64
- instance = new subject
65
-
66
- ::Telemetry.configure instance
67
- instance.configure(session: session)
68
- instance
69
- end
70
- end
71
-
72
- module RegisterTelemetrySink
73
- def register_telemetry_sink(storage)
74
- sink = Telemetry.sink
75
- storage.telemetry.register sink
76
- sink
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,15 +0,0 @@
1
- class EntityCache
2
- module Storage
3
- module Persistent
4
- class None
5
- include Persistent
6
-
7
- def get(*)
8
- end
9
-
10
- def put(*)
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,51 +0,0 @@
1
- class EntityCache
2
- module Storage
3
- module Persistent
4
- module Substitute
5
- def self.build
6
- substitute = Persistent.build :substitute
7
- sink = Persistent.register_telemetry_sink substitute
8
- substitute.sink = sink
9
- substitute
10
- end
11
-
12
- class Persistent
13
- attr_accessor :sink
14
-
15
- include Storage::Persistent
16
-
17
- def get(id)
18
- entity, version, time = records[id]
19
- return entity, version,time
20
- end
21
-
22
- def put(*)
23
- end
24
-
25
- def add(id, entity, version, time=nil)
26
- time ||= Clock::UTC.iso8601(precision: 5)
27
- records[id] ||= [entity, version, time]
28
- end
29
-
30
- def records
31
- @records ||= {}
32
- end
33
-
34
- module Assertions
35
- def retrieved?(&blk)
36
- sink.retrieved? &blk
37
- end
38
-
39
- def stored?(&blk)
40
- sink.stored? &blk
41
- end
42
-
43
- def stored_nothing?
44
- sink.put_records.empty?
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end