jaysylvester / comitium

Forum software for Node.js
MIT License
0 stars 1 forks source link

Rethink model cache scopes and keys #204

Open jaysylvester opened 2 years ago

jaysylvester commented 2 years ago

Model cache settings tend to follow this pattern:

let scope = 'discussion-' + discussion.id
let key = 'info'

This makes clearing all discussion caches difficult because it requires iterating over the set:

for ( let i = 0; i < discussions.rows.length; i++ ) {
  app.cache.clear({ scope: 'discussion-' + discussions.rows[i].id })
}

Cache scopes and keys such as the following would make it easier to clear groups of cache items:

let scope = 'discussion'
let key = 'discussion-' + discussion.id + '-info'

app.cache.clear({ scope: 'discussion' }) // Clear all discussion caches