tzispa_data 0.4.1 → 0.4.2

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: 5b0b31e17474d750c87dbc7376adbe897d4399d9
4
- data.tar.gz: 2447d842fc8016fc02ba8f5e0a3723953681218b
3
+ metadata.gz: f808bff654619a63929dffbfdfe1077e1719c22b
4
+ data.tar.gz: 0afaaf0f85f53846923f560e4cd303580ae0d3f4
5
5
  SHA512:
6
- metadata.gz: '0278a8c635236652bb18ab761ba9d91a6bef1f1cb6871b4cf1857eb7a15c2770a3a42c1851ee728043eee6732d4d41cb05510581bfb0437b4687b6ea14861806'
7
- data.tar.gz: 24d490046f5b820932ccd2a5fb2837cc2c66a3298088f34d8a486910e3f41ab2f00cd974a1850e2f1a4a5f0e2bacc1fb6831fc17ba5113186bdaf79d13c21dab
6
+ metadata.gz: 45fc47f896ae0048ba304f19ebc909f68ec45395dfea6953cb3e96cae7b1f5656fcc4e9180649ce0e927e5a8fbadf2ff784f22057c8f3263b4c329c7d841e2ab
7
+ data.tar.gz: efe05b00ac5a15a54d56fe667d2538eb54e40f0dcbd01ee78531c43ea6c79659074b709554722e4a112c5e30a445ef55a8dd721d516c34b6910329672b050ef2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  Tzispa Data
2
2
 
3
+ ## v0.4.2
4
+ - new cache system use Dalli for model Sequel caching
5
+ - independent caching per repository
6
+ - bugs fix
7
+
3
8
  ## 0.4.1
4
9
  - use redis for model cache
5
10
  - adapter pool optimizations and bugs fixes
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'sequel'
4
4
  require 'forwardable'
5
+ require 'dalli'
5
6
 
6
7
  module Tzispa
7
8
  module Data
@@ -11,16 +12,28 @@ module Tzispa
11
12
  extend Forwardable
12
13
 
13
14
  def_delegators :@pool, :has_key?, :keys
14
- attr_reader :default_repo
15
+ attr_reader :default_repo, :config, :pool
15
16
 
16
17
  def initialize(config, default = nil)
17
18
  setup_sequel
18
19
  @default_repo = default || config.first[0]
19
- @pool = {}.tap do |hsh|
20
+ @config = config
21
+ @pool ||= {}.tap do |hsh|
20
22
  config.each { |kid, vc| hsh[kid.to_sym] = connect(vc) }
21
23
  end
22
24
  end
23
25
 
26
+ def cache
27
+ @cache ||= {}.tap do |csh|
28
+ config.each do |kid, vc|
29
+ next unless vc.caching
30
+ csh[kid.to_sym] = Dalli::Client.new(vc.caching_server || DEFAULT_CACHING_SERVER,
31
+ namespace: kid.to_s,
32
+ compress: true)
33
+ end
34
+ end
35
+ end
36
+
24
37
  def connect(config)
25
38
  Sequel.connect("#{config.adapter}://#{config.database}").tap do |conn|
26
39
  if config.connection_validation
@@ -45,9 +58,12 @@ module Tzispa
45
58
  Sequel.extension :core_extensions
46
59
  Sequel.default_timezone = :utc
47
60
  Sequel.datetime_class = DateTime
61
+ Sequel.split_symbols = true
48
62
  end
49
63
 
50
64
  DEFAULT_TIMEOUT = 3600
65
+
66
+ DEFAULT_CACHING_SERVER = 'localhost:11211'
51
67
  end
52
68
 
53
69
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'sequel'
4
- require 'redis'
5
4
  require 'tzispa/utils/string'
6
5
  require 'tzispa/data/adapter_pool'
7
6
 
@@ -23,16 +22,6 @@ module Tzispa
23
22
 
24
23
  attr_reader :root, :adapters
25
24
 
26
- LOCAL_REPO_ROOT = :repository
27
-
28
- DEFAULT_CACHE_TTL = 900
29
-
30
- class << self
31
- def cache_client
32
- @cache_client ||= Redis.new(host: 'localhost')
33
- end
34
- end
35
-
36
25
  def initialize(config, root = nil)
37
26
  @config = config
38
27
  @root = root || LOCAL_REPO_ROOT
@@ -60,7 +49,6 @@ module Tzispa
60
49
  @config.each do |id, cfg|
61
50
  Mutex.new.synchronize do
62
51
  pool[id] = {}
63
- Sequel::Model.db = adapters[id]
64
52
  load_config_repo(id, cfg)
65
53
  domain.include module_const(id)
66
54
  end
@@ -69,12 +57,18 @@ module Tzispa
69
57
  end
70
58
 
71
59
  def register(model_id, model_class, repo_id, config)
72
- model_class.db = @adapters[repo_id]
73
- if config.caching
74
- model_class.plugin :caching, self.class.cache_client,
75
- ttl: config.ttl || DEFAULT_CACHE_TTL
60
+ unless pool[repo_id][model_id.to_sym]
61
+ unless model_class.db == adapters[repo_id]
62
+ model_class.db = adapters[repo_id]
63
+ if config.caching
64
+ model_class.plugin :caching, adapters.cache[repo_id],
65
+ ttl: config.ttl || DEFAULT_CACHE_TTL,
66
+ ignore_exceptions: true
67
+ end
68
+ end
69
+ pool[repo_id][model_id.to_sym] = model_class
76
70
  end
77
- @pool[repo_id][model_id.to_sym] = model_class
71
+ pool[repo_id][model_id.to_sym]
78
72
  end
79
73
 
80
74
  private
@@ -126,6 +120,10 @@ module Tzispa
126
120
  require "#{helpers_path}/#{helper_id}"
127
121
  end
128
122
  end
123
+
124
+ LOCAL_REPO_ROOT = :repository
125
+
126
+ DEFAULT_CACHE_TTL = 900
129
127
  end
130
128
 
131
129
  end
@@ -3,7 +3,7 @@
3
3
  module Tzispa
4
4
  module Data
5
5
 
6
- VERSION = '0.4.1'
6
+ VERSION = '0.4.2'
7
7
  NAME = 'Tzispa Data'
8
8
  GEM_NAME = 'tzispa_data'
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tzispa_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Antonio Piñero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-21 00:00:00.000000000 Z
11
+ date: 2017-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.31'
19
+ version: '4.44'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.31'
26
+ version: '4.44'
27
27
  - !ruby/object:Gem::Dependency
28
- name: redis
28
+ name: dalli
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.3'
33
+ version: '2.7'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.3'
40
+ version: '2.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: tzispa_utils
43
43
  requirement: !ruby/object:Gem::Requirement