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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aca46d5e864296ec667aad6a7ed0f679aee8463f
4
- data.tar.gz: 8e13a338781b0a8e32d27206b455a49a99b43fbf
3
+ metadata.gz: 85ef1e5e7ba8f3a9032104108c26ff2a4faa4980
4
+ data.tar.gz: dccc3b8bac1e420ae3d9357a2838aa80acf8b263
5
5
  SHA512:
6
- metadata.gz: eebfd2ca59a34e6be8df6862fa2a76c8146ed9ce270c644e3a05ad4d7a144712900fede5c9dd7f42dc86978c0b5081c5a44e7cfb7e1bca0f6e61ad29b1298b86
7
- data.tar.gz: e2ac284094bfc16c56787fb6958730f23f8e79926b4b644f95fe525069a36ebef71a82a440fd650c0cb287fd4a463aa1aabcc7eda821879c7bf0dff1ca920e3a
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 'telemetry/logger'
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/write_behind_delay'
11
+ require 'entity_cache/controls/persist_interval'
@@ -1,6 +1,6 @@
1
1
  class EntityCache
2
2
  module Controls
3
- module WriteBehindDelay
3
+ module PersistInterval
4
4
  module Exceeds
5
5
  def self.example
6
6
  Version.example - Version::Persistent.example
@@ -1,5 +1,13 @@
1
1
  class EntityCache
2
2
  module Controls
3
3
  Time = Clock::Controls::Time
4
+
5
+ module Time
6
+ def self.example(time=nil, precision: nil)
7
+ time ||= Raw.example
8
+ precision ||= 5
9
+ ISO8601.example(time, precision: precision)
10
+ end
11
+ end
4
12
  end
5
13
  end
@@ -5,7 +5,7 @@ class EntityCache
5
5
  11
6
6
  end
7
7
 
8
- module Age
8
+ module SincePersisted
9
9
  def self.example
10
10
  Version.example - Persistent.example
11
11
  end
@@ -3,9 +3,5 @@ class EntityCache
3
3
  def self.persistent_store
4
4
  Storage::Persistent::None
5
5
  end
6
-
7
- def self.write_behind_delay
8
- 10
9
- end
10
6
  end
11
7
  end
@@ -1,65 +1,67 @@
1
1
  class EntityCache
2
- configure :entity_cache
2
+ Error = Class.new(RuntimeError)
3
3
 
4
- attr_reader :write_behind_delay
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 initialize(write_behind_delay=nil)
12
- @write_behind_delay = write_behind_delay
13
- end
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 write_behind_delay
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 instance, subject
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.opt_trace "Reading cache (ID: #{id.inspect})"
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.opt_debug "Cache miss (ID: #{id.inspect})"
39
+ logger.info { "Cache miss (ID: #{id.inspect})" }
38
40
  return nil
39
41
  end
40
42
 
41
- logger.opt_debug "Cache hit (ID: #{id.inspect}, Entity Class: #{record.entity.class.name}, Version: #{record.version.inspect}, Time: #{record.time})"
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.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})"
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.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})"
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 write_behind_delay && record.age >= write_behind_delay
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
 
@@ -0,0 +1,9 @@
1
+ class EntityCache
2
+ class Log < ::Log
3
+ def tag!(tags)
4
+ tags << :entity_cache
5
+ tags << :library
6
+ tags << :verbose
7
+ end
8
+ end
9
+ end
@@ -1,6 +1,6 @@
1
1
  class EntityCache
2
2
  class Record < Struct.new :id, :entity, :version, :time, :persisted_version, :persisted_time
3
- def age
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 :configure_dependencies unless instance_methods.include?(:configure_dependencies)
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.opt_trace "Getting entity (ID: #{id.inspect})"
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.opt_debug "Got entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})"
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.opt_trace "Putting entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})"
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.opt_debug "Put entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})"
56
+ logger.debug { "Put entity (ID: #{id.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time.inspect})" }
54
57
 
55
- time
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
- ::Telemetry::Logger.configure instance
65
+
63
66
  ::Telemetry.configure instance
64
- instance.configure_dependencies
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
@@ -23,7 +23,7 @@ class EntityCache
23
23
  end
24
24
 
25
25
  def add(id, entity, version, time=nil)
26
- time ||= Clock::UTC.iso8601
26
+ time ||= Clock::UTC.iso8601(precision: 5)
27
27
  records[id] ||= [entity, version, time]
28
28
  end
29
29
 
@@ -1,9 +1,9 @@
1
1
  class EntityCache
2
2
  module Storage
3
3
  class Temporary
4
- attr_reader :subject
4
+ include Log::Dependency
5
5
 
6
- dependency :logger, Telemetry::Logger
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
 
@@ -34,7 +34,7 @@ class EntityCache
34
34
  end
35
35
 
36
36
  def self.logger
37
- @logger ||= Telemetry::Logger.get self
37
+ @logger ||= Log.get(self)
38
38
  end
39
39
  end
40
40
  end
@@ -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
- instance = new
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.6.1.1
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-22 00:00:00.000000000 Z
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-logger
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.2.3
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.6.8
176
+ rubygems_version: 2.5.2
161
177
  signing_key:
162
178
  specification_version: 4
163
179
  summary: Entity cache