Potential difference between default and custom cache adapter
dricholm opened this issue · comments
Hello @rjyo,
I just started trying out the library and it looks promising so far. I have a question or maybe a bug report.
When using the .next-boost.js
config file, the path to the cache can be supplied in the cache.path
property. However it seems this is not passed to the default Cache.init()
when cacheAdapter
is not provided in the config. This results in all options using the default, path being \tmp\hdc
.
> Preparing cached handler
Loaded next-boost config from .next-boost.js
// Logging the merged conflict shows all the options
// Logging from next-boost-hdc-adapter's init shows undefined
Cache located at \tmp\hdc
Cache manager inited, will start to purge in 3600s
A workaround I found is to pass the adapter itself in the .next-boost.js
config file:
cacheAdapter: hdcAdapter.init({
path: path.join(__dirname, 'cache'),
}),
Could this be fixed so we don't have to create the adapter outside?
Another thing I noticed is that in Handler's close
shutdown()
is called on the default Cache
object. Should this be called on the above created cache
instead? Otherwise the provided cache's shutdown()
would never be called.
Thank you!
Thanks for the reporting.
As I have added support for different cache adapters, now you need to pass the adapter from .next-boost.js
in the latest version. Thus you can have flexible initial configurations for different types of cache adapters.
This also decouples the original hybrid-disk-cache
from next-boost
. So when you are using redis-cache
, you don't have to install sqlite3
related node modules (which have native code compiling and are slow).
// An example with redis adapter
const Adapter = require('@next-boost/redis-cache').Adapter
module.exports = {
...
cacheAdapter: new Adapter({
uri: 'redis://127.0.0.1:6379/1',
ttl: 60,
tbd: 3600,
}),
}
// An example with hybrid-disk-cache adapter
const Adapter = require('@next-boost/hybrid-disk-cache').Adapter
module.exports = {
...
cacheAdapter: new Adapter({
path: '/tmp/hdc',
ttl: 60,
tbd: 3600,
}),
}