evt-entity_cache 0.6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/entity_cache.rb +22 -0
- data/lib/entity_cache/controls.rb +11 -0
- data/lib/entity_cache/controls/entity.rb +9 -0
- data/lib/entity_cache/controls/id.rb +5 -0
- data/lib/entity_cache/controls/record.rb +25 -0
- data/lib/entity_cache/controls/storage/persistent.rb +39 -0
- data/lib/entity_cache/controls/storage/temporary.rb +11 -0
- data/lib/entity_cache/controls/time.rb +5 -0
- data/lib/entity_cache/controls/version.rb +27 -0
- data/lib/entity_cache/controls/write_behind_delay.rb +29 -0
- data/lib/entity_cache/defaults.rb +11 -0
- data/lib/entity_cache/entity_cache.rb +83 -0
- data/lib/entity_cache/record.rb +39 -0
- data/lib/entity_cache/storage/persistent.rb +80 -0
- data/lib/entity_cache/storage/persistent/none.rb +15 -0
- data/lib/entity_cache/storage/persistent/substitute.rb +51 -0
- data/lib/entity_cache/storage/persistent/telemetry.rb +38 -0
- data/lib/entity_cache/storage/temporary.rb +57 -0
- data/lib/entity_cache/storage/temporary/factory.rb +42 -0
- data/lib/entity_cache/storage/temporary/scope.rb +30 -0
- data/lib/entity_cache/storage/temporary/scope/exclusive.rb +13 -0
- data/lib/entity_cache/storage/temporary/scope/shared.rb +17 -0
- data/lib/entity_cache/substitute.rb +44 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aca46d5e864296ec667aad6a7ed0f679aee8463f
|
4
|
+
data.tar.gz: 8e13a338781b0a8e32d27206b455a49a99b43fbf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eebfd2ca59a34e6be8df6862fa2a76c8146ed9ce270c644e3a05ad4d7a144712900fede5c9dd7f42dc86978c0b5081c5a44e7cfb7e1bca0f6e61ad29b1298b86
|
7
|
+
data.tar.gz: e2ac284094bfc16c56787fb6958730f23f8e79926b4b644f95fe525069a36ebef71a82a440fd650c0cb287fd4a463aa1aabcc7eda821879c7bf0dff1ca920e3a
|
data/lib/entity_cache.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'configure'; Configure.activate
|
2
|
+
require 'settings'; Settings.activate
|
3
|
+
require 'telemetry'
|
4
|
+
require 'telemetry/logger'
|
5
|
+
require 'virtual'; Virtual.activate
|
6
|
+
|
7
|
+
require 'entity_cache/record'
|
8
|
+
|
9
|
+
require 'entity_cache/storage/persistent'
|
10
|
+
require 'entity_cache/storage/persistent/none'
|
11
|
+
require 'entity_cache/storage/persistent/substitute'
|
12
|
+
require 'entity_cache/storage/persistent/telemetry'
|
13
|
+
|
14
|
+
require 'entity_cache/storage/temporary'
|
15
|
+
require 'entity_cache/storage/temporary/factory'
|
16
|
+
require 'entity_cache/storage/temporary/scope'
|
17
|
+
require 'entity_cache/storage/temporary/scope/exclusive'
|
18
|
+
require 'entity_cache/storage/temporary/scope/shared'
|
19
|
+
|
20
|
+
require 'entity_cache/defaults'
|
21
|
+
require 'entity_cache/entity_cache'
|
22
|
+
require 'entity_cache/substitute'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'clock/controls'
|
2
|
+
require 'identifier/uuid/controls'
|
3
|
+
|
4
|
+
require 'entity_cache/controls/entity'
|
5
|
+
require 'entity_cache/controls/id'
|
6
|
+
require 'entity_cache/controls/record'
|
7
|
+
require 'entity_cache/controls/storage/persistent'
|
8
|
+
require 'entity_cache/controls/storage/temporary'
|
9
|
+
require 'entity_cache/controls/time'
|
10
|
+
require 'entity_cache/controls/version'
|
11
|
+
require 'entity_cache/controls/write_behind_delay'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class EntityCache
|
2
|
+
module Controls
|
3
|
+
module Record
|
4
|
+
def self.example(id=nil, version: nil, persisted_version: nil)
|
5
|
+
id ||= ID.example
|
6
|
+
entity = Entity.example
|
7
|
+
version ||= Version.example
|
8
|
+
persisted_version ||= Version::Persistent.example
|
9
|
+
|
10
|
+
time = Time.example
|
11
|
+
persisted_time = time
|
12
|
+
|
13
|
+
EntityCache::Record.new id, entity, version, time, persisted_version, persisted_time
|
14
|
+
end
|
15
|
+
|
16
|
+
module Persisted
|
17
|
+
def self.example(id=nil)
|
18
|
+
version = Version::Persistent.example
|
19
|
+
|
20
|
+
Record.example id, version: version
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class EntityCache
|
2
|
+
module Controls
|
3
|
+
module Storage
|
4
|
+
module Persistent
|
5
|
+
class Example
|
6
|
+
include EntityCache::Storage::Persistent
|
7
|
+
|
8
|
+
def get(id)
|
9
|
+
entity, version, time = records[id]
|
10
|
+
|
11
|
+
return entity, version, time
|
12
|
+
end
|
13
|
+
|
14
|
+
def put(id, entity, version, time)
|
15
|
+
records[id] = [entity, version, time]
|
16
|
+
end
|
17
|
+
|
18
|
+
def records
|
19
|
+
@records ||= {}
|
20
|
+
end
|
21
|
+
|
22
|
+
module Assertions
|
23
|
+
def stored?(id, entity, version, time)
|
24
|
+
records[id] == [entity, version, time]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.example
|
30
|
+
Example.build :some_subject
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.substitute
|
34
|
+
SubstAttr::Substitute.build Example
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class EntityCache
|
2
|
+
module Controls
|
3
|
+
module Version
|
4
|
+
def self.example
|
5
|
+
11
|
6
|
+
end
|
7
|
+
|
8
|
+
module Age
|
9
|
+
def self.example
|
10
|
+
Version.example - Persistent.example
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module NoStream
|
15
|
+
def self.example
|
16
|
+
EntityCache::Record::NoStream.version
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Persistent
|
21
|
+
def self.example
|
22
|
+
1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class EntityCache
|
2
|
+
module Controls
|
3
|
+
module WriteBehindDelay
|
4
|
+
module Exceeds
|
5
|
+
def self.example
|
6
|
+
Version.example - Version::Persistent.example
|
7
|
+
end
|
8
|
+
|
9
|
+
module NoStream
|
10
|
+
def self.example
|
11
|
+
Version.example
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Within
|
17
|
+
def self.example
|
18
|
+
Exceeds.example + 1
|
19
|
+
end
|
20
|
+
|
21
|
+
module NoStream
|
22
|
+
def self.example
|
23
|
+
Exceeds::NoStream.example + 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class EntityCache
|
2
|
+
configure :entity_cache
|
3
|
+
|
4
|
+
attr_reader :write_behind_delay
|
5
|
+
|
6
|
+
dependency :clock, Clock::UTC
|
7
|
+
dependency :logger, Telemetry::Logger
|
8
|
+
dependency :persistent_store, Storage::Persistent
|
9
|
+
dependency :temporary_store, Storage::Temporary
|
10
|
+
|
11
|
+
def initialize(write_behind_delay=nil)
|
12
|
+
@write_behind_delay = write_behind_delay
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.build(subject, persistent_store: nil, write_behind_delay: nil)
|
16
|
+
persistent_store ||= Defaults.persistent_store
|
17
|
+
write_behind_delay ||= Defaults.write_behind_delay
|
18
|
+
|
19
|
+
instance = new write_behind_delay
|
20
|
+
|
21
|
+
Clock::UTC.configure instance
|
22
|
+
Telemetry::Logger.configure instance
|
23
|
+
Storage::Temporary.configure instance, subject
|
24
|
+
|
25
|
+
persistent_store.configure instance, subject
|
26
|
+
|
27
|
+
instance
|
28
|
+
end
|
29
|
+
|
30
|
+
def get(id)
|
31
|
+
logger.opt_trace "Reading cache (ID: #{id.inspect})"
|
32
|
+
|
33
|
+
record = temporary_store.get id
|
34
|
+
record ||= restore id
|
35
|
+
|
36
|
+
if record.nil?
|
37
|
+
logger.opt_debug "Cache miss (ID: #{id.inspect})"
|
38
|
+
return nil
|
39
|
+
end
|
40
|
+
|
41
|
+
logger.opt_debug "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
|
48
|
+
|
49
|
+
logger.opt_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
|
+
|
51
|
+
record = Record.new id, entity, version, time, persisted_version, persisted_time
|
52
|
+
|
53
|
+
put_record record
|
54
|
+
|
55
|
+
logger.opt_debug "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
|
+
|
57
|
+
record
|
58
|
+
end
|
59
|
+
|
60
|
+
def put_record(record)
|
61
|
+
if write_behind_delay && record.age >= write_behind_delay
|
62
|
+
persisted_time = clock.iso8601
|
63
|
+
|
64
|
+
persistent_store.put record.id, record.entity, record.version, persisted_time
|
65
|
+
|
66
|
+
record.persisted_version = record.version
|
67
|
+
record.persisted_time = persisted_time
|
68
|
+
end
|
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
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class EntityCache
|
2
|
+
class Record < Struct.new :id, :entity, :version, :time, :persisted_version, :persisted_time
|
3
|
+
def age
|
4
|
+
persisted_version = self.persisted_version
|
5
|
+
persisted_version ||= -1
|
6
|
+
|
7
|
+
version - persisted_version.to_i
|
8
|
+
end
|
9
|
+
|
10
|
+
def destructure(includes=nil)
|
11
|
+
return entity if includes.nil?
|
12
|
+
|
13
|
+
responses = [entity]
|
14
|
+
|
15
|
+
includes = Array(includes)
|
16
|
+
|
17
|
+
includes.each do |attribute|
|
18
|
+
value = public_send attribute
|
19
|
+
|
20
|
+
value = NoStream.version if value.nil? && attribute == :version
|
21
|
+
|
22
|
+
responses << value
|
23
|
+
end
|
24
|
+
|
25
|
+
responses
|
26
|
+
end
|
27
|
+
|
28
|
+
module NoStream
|
29
|
+
def self.destructure(includes=nil)
|
30
|
+
record = Record.new
|
31
|
+
record.destructure includes
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.version
|
35
|
+
:no_stream
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class EntityCache
|
2
|
+
module Storage
|
3
|
+
module Persistent
|
4
|
+
extend Configure::Macro
|
5
|
+
|
6
|
+
def self.included(cls)
|
7
|
+
cls.class_exec do
|
8
|
+
configure :persistent_store
|
9
|
+
|
10
|
+
dependency :logger, ::Telemetry::Logger
|
11
|
+
dependency :telemetry, ::Telemetry
|
12
|
+
|
13
|
+
extend Build
|
14
|
+
extend RegisterTelemetrySink
|
15
|
+
|
16
|
+
prepend Get
|
17
|
+
prepend Put
|
18
|
+
|
19
|
+
virtual :configure_dependencies unless instance_methods.include?(:configure_dependencies)
|
20
|
+
abstract :get unless instance_methods.include?(:get)
|
21
|
+
abstract :put unless instance_methods.include?(:put)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :subject
|
26
|
+
|
27
|
+
def initialize(subject)
|
28
|
+
@subject = subject
|
29
|
+
end
|
30
|
+
|
31
|
+
module Get
|
32
|
+
def get(id)
|
33
|
+
logger.opt_trace "Getting entity (ID: #{id.inspect})"
|
34
|
+
|
35
|
+
entity, version, time = super
|
36
|
+
|
37
|
+
telemetry.record :get, Telemetry::Data.new(id, entity, version, time)
|
38
|
+
|
39
|
+
logger.opt_debug "Got entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})"
|
40
|
+
|
41
|
+
return entity, version, time
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module Put
|
46
|
+
def put(id, entity, version, time)
|
47
|
+
logger.opt_trace "Putting entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})"
|
48
|
+
|
49
|
+
super
|
50
|
+
|
51
|
+
telemetry.record :put, Telemetry::Data.new(id, entity, version, time)
|
52
|
+
|
53
|
+
logger.opt_debug "Put entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})"
|
54
|
+
|
55
|
+
time
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
module Build
|
60
|
+
def build(subject)
|
61
|
+
instance = new subject
|
62
|
+
::Telemetry::Logger.configure instance
|
63
|
+
::Telemetry.configure instance
|
64
|
+
instance.configure_dependencies
|
65
|
+
instance
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
module RegisterTelemetrySink
|
70
|
+
def register_telemetry_sink(storage)
|
71
|
+
sink = Telemetry.sink
|
72
|
+
storage.telemetry.register sink
|
73
|
+
sink
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
Error = Class.new StandardError
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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
|
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
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class EntityCache
|
2
|
+
module Storage
|
3
|
+
module Persistent
|
4
|
+
module Telemetry
|
5
|
+
def self.sink
|
6
|
+
Sink.new
|
7
|
+
end
|
8
|
+
|
9
|
+
Data = Struct.new :id, :entity, :version, :time
|
10
|
+
|
11
|
+
class Sink
|
12
|
+
include ::Telemetry::Sink
|
13
|
+
|
14
|
+
record :get
|
15
|
+
record :put
|
16
|
+
|
17
|
+
def retrieved?(&blk)
|
18
|
+
return get_records if blk.nil?
|
19
|
+
|
20
|
+
recorded_get? do |record|
|
21
|
+
data = record.data
|
22
|
+
blk.call(data.id, data.entity, data.version, data.time)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def stored?(&blk)
|
27
|
+
return put_records if blk.nil?
|
28
|
+
|
29
|
+
recorded_put? do |record|
|
30
|
+
data = record.data
|
31
|
+
blk.call(data.id, data.entity, data.version, data.time)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class EntityCache
|
2
|
+
module Storage
|
3
|
+
class Temporary
|
4
|
+
attr_reader :subject
|
5
|
+
|
6
|
+
dependency :logger, Telemetry::Logger
|
7
|
+
|
8
|
+
def initialize(subject)
|
9
|
+
@subject = subject
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.build(subject)
|
13
|
+
instance = new subject
|
14
|
+
Telemetry::Logger.configure instance
|
15
|
+
instance
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure(receiver, subject, scope: nil, attr_name: nil)
|
19
|
+
attr_name ||= :temporary_store
|
20
|
+
|
21
|
+
instance = Factory.(subject, scope: scope)
|
22
|
+
receiver.public_send "#{attr_name}=", instance
|
23
|
+
instance
|
24
|
+
end
|
25
|
+
|
26
|
+
def get(id)
|
27
|
+
records[id]
|
28
|
+
end
|
29
|
+
|
30
|
+
def put(record)
|
31
|
+
records[record.id] = record
|
32
|
+
end
|
33
|
+
|
34
|
+
abstract :records
|
35
|
+
|
36
|
+
module Assertions
|
37
|
+
def empty?
|
38
|
+
records.empty?
|
39
|
+
end
|
40
|
+
|
41
|
+
def put?(&block)
|
42
|
+
block ||= proc { true }
|
43
|
+
|
44
|
+
records.any? do |_, record|
|
45
|
+
block.(record)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module Substitute
|
51
|
+
def self.build
|
52
|
+
Scope::Exclusive.build :substitute
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class EntityCache
|
2
|
+
module Storage
|
3
|
+
class Temporary
|
4
|
+
module Factory
|
5
|
+
def self.call(subject, scope: nil)
|
6
|
+
scope ||= Scope::Defaults::Name.get
|
7
|
+
|
8
|
+
scope_class = self.scope_class scope
|
9
|
+
|
10
|
+
scope_class.build subject
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.scope_class(scope_name)
|
14
|
+
scope_class = scopes[scope_name]
|
15
|
+
|
16
|
+
if scope_class.nil?
|
17
|
+
*scopes, final_scope = self.scopes.keys
|
18
|
+
scopes = "#{scopes * ', '} or #{scope_name}"
|
19
|
+
|
20
|
+
error_message = %{Scope "#{scope_name}" is unknown. It must be one of: #{scopes}}
|
21
|
+
|
22
|
+
logger.error error_message
|
23
|
+
raise Scope::Error, error_message
|
24
|
+
end
|
25
|
+
|
26
|
+
scope_class
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.scopes
|
30
|
+
@scopes ||= {
|
31
|
+
:exclusive => Scope::Exclusive,
|
32
|
+
:shared => Scope::Shared
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.logger
|
37
|
+
@logger ||= Telemetry::Logger.get self
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class EntityCache
|
2
|
+
module Storage
|
3
|
+
class Temporary
|
4
|
+
module Scope
|
5
|
+
Error = Class.new StandardError
|
6
|
+
|
7
|
+
module Defaults
|
8
|
+
module Name
|
9
|
+
def self.get
|
10
|
+
value = env_var_value || self.value
|
11
|
+
value.to_sym
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.env_var_value
|
15
|
+
ENV[env_var_name]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.env_var_name
|
19
|
+
'ENTITY_CACHE_SCOPE'
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.value
|
23
|
+
'shared'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class EntityCache
|
2
|
+
module Substitute
|
3
|
+
def self.build
|
4
|
+
EntityCache.build
|
5
|
+
end
|
6
|
+
|
7
|
+
class EntityCache < EntityCache
|
8
|
+
def self.build
|
9
|
+
instance = new
|
10
|
+
Telemetry::Logger.configure instance
|
11
|
+
instance
|
12
|
+
end
|
13
|
+
|
14
|
+
def add(id, entity, version=nil, persisted_version: nil)
|
15
|
+
version ||= 0
|
16
|
+
persisted_version ||= version
|
17
|
+
|
18
|
+
time = clock.iso8601
|
19
|
+
|
20
|
+
record = Record.new id, entity, version, time, persisted_version, time
|
21
|
+
|
22
|
+
temporary_store.put record
|
23
|
+
end
|
24
|
+
|
25
|
+
def put_record(record)
|
26
|
+
put_records << record
|
27
|
+
end
|
28
|
+
|
29
|
+
def put_records
|
30
|
+
@put_records ||= []
|
31
|
+
end
|
32
|
+
|
33
|
+
module Assertions
|
34
|
+
def put?(&blk)
|
35
|
+
return put_records.any? if blk.nil?
|
36
|
+
|
37
|
+
put_records.any? do |record|
|
38
|
+
blk.(record)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: evt-entity_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- The Eventide Project
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: evt-configure
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: evt-settings
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: evt-telemetry-logger
|
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-virtual
|
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: test_bench
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: " "
|
112
|
+
email: opensource@eventide-project.org
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- lib/entity_cache.rb
|
118
|
+
- lib/entity_cache/controls.rb
|
119
|
+
- lib/entity_cache/controls/entity.rb
|
120
|
+
- lib/entity_cache/controls/id.rb
|
121
|
+
- lib/entity_cache/controls/record.rb
|
122
|
+
- lib/entity_cache/controls/storage/persistent.rb
|
123
|
+
- lib/entity_cache/controls/storage/temporary.rb
|
124
|
+
- lib/entity_cache/controls/time.rb
|
125
|
+
- lib/entity_cache/controls/version.rb
|
126
|
+
- lib/entity_cache/controls/write_behind_delay.rb
|
127
|
+
- lib/entity_cache/defaults.rb
|
128
|
+
- lib/entity_cache/entity_cache.rb
|
129
|
+
- lib/entity_cache/record.rb
|
130
|
+
- lib/entity_cache/storage/persistent.rb
|
131
|
+
- lib/entity_cache/storage/persistent/none.rb
|
132
|
+
- lib/entity_cache/storage/persistent/substitute.rb
|
133
|
+
- lib/entity_cache/storage/persistent/telemetry.rb
|
134
|
+
- lib/entity_cache/storage/temporary.rb
|
135
|
+
- lib/entity_cache/storage/temporary/factory.rb
|
136
|
+
- lib/entity_cache/storage/temporary/scope.rb
|
137
|
+
- lib/entity_cache/storage/temporary/scope/exclusive.rb
|
138
|
+
- lib/entity_cache/storage/temporary/scope/shared.rb
|
139
|
+
- lib/entity_cache/substitute.rb
|
140
|
+
homepage: https://github.com/eventide-project/entity-cache
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 2.2.3
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.6.8
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Entity cache
|
164
|
+
test_files: []
|