Closed jaumard closed 7 years ago
My proposal:
All store under config.caches.stores
should be create and accessible by getCaches(name)
. For multi-instances we can do something like this:
stores: [
['memory', 'mongo'],//multi-instance
{
name: 'memory',
type: 'memory',
max: 100,
ttl: 0
},{
name: 'mongo',
type: 'mongodb',
max: 100,
ttl: 0
}
]
So no more defaults
because it's not needed.
What do you think @maissani ?
My opinion about trailpack-cache is :
getCaches() => Get Defaults Cache
getCaches(Array) => Get MultiCache Instance
getCache(name) => Get Single Cache Instance
#Thoses functions will return promises so getCaches().done((value) =>{
console.log('the variable'+value+' has been successfully stored on cache')
})
So obviously default is needed because we need at least 1 store for cache. My second opinion about stores is that , stores should only contain an array of stores configuration, if you want to set a set of multi stores i think we should do that :
# By default the first configuration or configuration named: 'default' is loaded
configurations: [
{
name: default,
stores: ['memory', 'mongo'']
},
{
name: 'custom';
stores: ['mongo', 'redis']
}]
stores: [{
name: 'memory',
type: 'memory',
max: 100,
ttl: 0
}......]
To change configuration you will have to do
this.app.CacheService.setStoreConfiguration('configurationname').getChaches() => return multi Stores Instances for the given configuration
this.app.CacheService..getChaches() => return defaults stores Instance ( single or multi )
getCaches() => Get Defaults Cache getCaches(Array) => Get MultiCache Instance getCache(name) => Get Single Cache Instance
Sound good to me but you'll have to find a way to store your singleton for Array.
this.app.CacheService.setStoreConfiguration('configurationname').getChaches() => return multi Stores Instances for the given configuration
Don't like it at all, it's not natural to use it like this. And I think it's not needed because if you want to retrieve multi cache users can do getCaches(['mongo', 'redis'])
so don't need all those configuration things
What the purpose of config.caches.defaults ? Because if we didn't specify all store in it they are not available at all...