bajo-template 2.5.2 → 2.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -25,7 +25,7 @@ async function factory (pkgName) {
25
25
  },
26
26
  loopDetectorDur: '1m',
27
27
  cache: {
28
- maxAgeDur: '1s'
28
+ ttlDur: '1s'
29
29
  }
30
30
  }
31
31
  this.loopDetector = {}
@@ -239,23 +239,20 @@ async function factory (pkgName) {
239
239
  }
240
240
 
241
241
  compile = async (content, locals, { lang, ttl = 0 } = {}) => {
242
- locals.attr = locals.attr ?? {}
242
+ const { get: getCache, set: setCache } = this.app.bajoCache ?? {}
243
243
  const { template } = this.app.lib._
244
- const cache = this.app.bajoCache
245
- let canCache = this.config.cache !== false && cache && this.app.bajo.config.env !== 'dev'
246
- if (ttl === -1) canCache = false
244
+ locals.attr = locals.attr ?? {}
247
245
  const opts = {
248
246
  imports: this.buildCompileImports(lang)
249
247
  }
250
-
248
+ const key = 'fn:' + crypto.createHash('md5').update(content).digest('hex')
251
249
  let item
252
- if (canCache) {
253
- const key = 'fn:' + crypto.createHash('md5').update(content).digest('hex')
254
- const value = template(content, opts)
255
- item = await cache.sync({ key, value, ttl })
256
- } else {
257
- item = template(content, opts)
250
+ if (getCache) {
251
+ item = await getCache({ key })
252
+ if (item) return item(locals)
258
253
  }
254
+ item = template(content, opts)
255
+ if (setCache) await setCache({ key, value: item, ttl })
259
256
  return item(locals)
260
257
  }
261
258
 
@@ -273,7 +270,7 @@ async function factory (pkgName) {
273
270
  let subNs
274
271
  const isAbsolute = path.isAbsolute(tpl)
275
272
  if (!isAbsolute) subNs = breakNsPath(tpl).subNs
276
- const canCache = (isAbsolute || subNs === 'template') && this.config.cache !== false && cache && this.app.bajo.config.env !== 'dev'
273
+ const canCache = (isAbsolute || subNs === 'template') && this.config.cache !== false && cache
277
274
  if (canCache) {
278
275
  const item = await cache.get({ key })
279
276
  if (item) return item
@@ -282,7 +279,7 @@ async function factory (pkgName) {
282
279
  let text = await this._render(tpl, locals, opts)
283
280
  if (opts.postProcessor) text = await opts.postProcessor({ text, locals, opts })
284
281
  if (subNs) await runHook(`${this.ns}:afterRender${upperFirst(subNs)}`, { tpl, locals, opts, text })
285
- if (canCache) await cache.set({ key, value: text, ttl: opts.cacheMaxAge ?? this.config.cache.maxAgeDur })
282
+ if (canCache) await cache.set({ key, value: text, ttl: opts.ttlDur ?? this.config.cache.ttlDur })
286
283
  return text
287
284
  }
288
285
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo-template",
3
- "version": "2.5.2",
3
+ "version": "2.5.4",
4
4
  "description": "Template Renderer for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,12 +1,17 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-25
4
+
5
+ - [2.5.3] Bug fix in cache handling for template function
6
+ - [2.5.4] Change ```maxAgeDur``` to ```ttlDur``` to align with bajoCache's terminology
7
+
3
8
  ## 2026-03-14
4
9
 
5
- - [2.5.2] Bug fix on ```resolveResource()```
10
+ - [2.5.2] Bug fix in ```resolveResource()```
6
11
 
7
12
  ## 2026-02-21
8
13
 
9
- - [2.5.1] Bug fix on layout fallback
14
+ - [2.5.1] Bug fix in layout fallback
10
15
  - [2.5.1] Refactoring ```resolveResource()``` to be more modular
11
16
 
12
17
  ## 2026-02-17
@@ -24,7 +29,7 @@
24
29
 
25
30
  ## 2026-02-05
26
31
 
27
- - [2.2.2] Bug fix on front matter parsing
32
+ - [2.2.2] Bug fix in front matter parsing
28
33
 
29
34
  ## 2026-01-21
30
35