tzispa_rig 0.3.3 → 0.3.4

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: 47caf9d29bcf57c26262b3cbde5513060b677f23
4
- data.tar.gz: cc3036e2437a2eadcdda3a6c0c2ef3fc5c97279b
3
+ metadata.gz: 34c29a6d0cb71518ba08bf0c7c3274ac6a1cad35
4
+ data.tar.gz: 23a5a9a18a5d22e871a51b5085d730b47f4676ff
5
5
  SHA512:
6
- metadata.gz: 2a773cca4ef477089298ec6b70856303429869bfcae2412a058cbd257fdc37a25e87521c5ba1b052706d9477653bfd419ece1d2f6fecfcd244b34a34034f23d1
7
- data.tar.gz: f80a648340d0a6a06c76d700956e6de301f8fa3d80e73e911dcfb0b6d46adcafb4f76d265b4f427f449565b5d9fd3f440a4adae3ecb0a098e172b49944f711e9
6
+ metadata.gz: 2780edabd2cbf6d049860a10eb04363c094a9b851a5ec95fd3b394cb34389b483cb4613418f7430bc791f942c9b3d55143d73853cd985402207be25e5deceb59
7
+ data.tar.gz: 8bbffe98a3a17c8a33d646980bc95f1ce3e7828f8779d323230c95b51d1897b335b3b5c2b67c5fc18b525085f94770ea0778b8c6def762b34028df2e88d71914
data/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@ Tzispa Rig
2
2
 
3
3
  Rig templates implementation
4
4
 
5
+ ## 0.3.4
6
+ - fix template cache returning empty template sometimes
7
+
5
8
  ## 0.3.3
6
9
  - Raise a custom exception when a binder tag does not exists in the template
7
10
  - Raise custom exception when there are duplicated loops in binder
@@ -13,8 +13,7 @@ module Tzispa
13
13
 
14
14
  def initialize(app, cache_enabled, cache_size)
15
15
  @app = app
16
- @cache = LruRedux::Cache.new(cache_size) if cache_enabled
17
- @mutex = Mutex.new
16
+ @cache = LruRedux::ThreadSafeCache.new(cache_size) if cache_enabled
18
17
  end
19
18
 
20
19
  def layout(name:, format:nil, params:nil)
@@ -31,13 +30,7 @@ module Tzispa
31
30
 
32
31
  def rig_template(name, type, tpl_format, params, parent)
33
32
  if @cache
34
- if @mutex.owned?
35
- cache_template(name, type, tpl_format, params, parent)
36
- else
37
- @mutex.synchronize {
38
- cache_template(name, type, tpl_format, params, parent)
39
- }
40
- end
33
+ cache_template(name, type, tpl_format, params, parent)
41
34
  else
42
35
  Template.new(name: name, type: type, format: tpl_format, domain: @app.domain, params: params, parent: parent, engine: self).load!.parse!
43
36
  end
@@ -46,18 +39,25 @@ module Tzispa
46
39
  private
47
40
 
48
41
  def cache_template(name, type, tpl_format, params, parent)
49
- ktpl = "#{type}__#{name}".to_sym
50
- tpl = @cache.getset(ktpl) {
51
- Template.new(name: name, type: type, format: tpl_format, domain: @app.domain, parent: parent, engine: self).load!.parse!
52
- }
53
- if tpl.modified?
54
- tpl = @cache[ktpl] = Template.new(name: name, type: type, format: tpl_format, domain: @app.domain, parent: parent, engine: self).load!.parse!
55
- end
56
- tpl.dup.tap { |ctpl|
42
+ key = "#{type}__#{name}".to_sym
43
+ (get_template(key, name, type, tpl_format, parent) || set_template(key, name, type, tpl_format, parent)).dup.tap { |ctpl|
57
44
  ctpl.params = params if params
58
45
  }
59
46
  end
60
47
 
48
+ def get_template(key, name, type, tpl_format, parent)
49
+ if @cache.key?(key) && (@cache[key].modified? || !@cache[key].valid?)
50
+ set_template(key, name, type, tpl_format, parent)
51
+ else
52
+ @cache[key]
53
+ end
54
+ end
55
+
56
+
57
+ def set_template(key, name, type, tpl_format, parent)
58
+ @cache[key] = Template.new(name: name, type: type, format: tpl_format, domain: @app.domain, parent: parent, engine: self).load!.parse!
59
+ end
60
+
61
61
  end
62
62
 
63
63
  end
@@ -349,6 +349,10 @@ module Tzispa
349
349
  @the_parsed = Array.new
350
350
  end
351
351
 
352
+ def empty?
353
+ @the_parsed.empty?
354
+ end
355
+
352
356
  def parse!
353
357
  @tags = nil
354
358
  parse_flags
@@ -101,6 +101,10 @@ module Tzispa
101
101
  })
102
102
  end
103
103
 
104
+ def valid?
105
+ !content.empty? && !parser.empty?
106
+ end
107
+
104
108
  def render(context)
105
109
  parse! unless @parser
106
110
  binder = TemplateBinder.for self, context
@@ -3,7 +3,7 @@
3
3
  module Tzispa
4
4
  module Rig
5
5
 
6
- VERSION = '0.3.3'
6
+ VERSION = '0.3.4'
7
7
  GEM_NAME = 'tzispa_rig'
8
8
 
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tzispa_rig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
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: 2016-05-23 00:00:00.000000000 Z
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzispa_helpers