fabioricali / incache Goto Github PK
View Code? Open in Web Editor NEWPowerful key/value in-memory storage or on disk to persist data
Powerful key/value in-memory storage or on disk to persist data
It took me actually a while to figure it out why I was having this issue once running the latest version of this library:
Unhandled Rejection at: Promise { <rejected> 'fs.writeFileSync is not a function' } reason: fs.writeFileSync is not a function
Once I found out that in your webpack config, you have this line that is very wrong if you build the library using webpack.
As suggested by Webpack itself, please use target: 'node'
instead.
Thank you in advance :)
For whoever has an issue, this is the workaround you can use:
// Generic require way
const incache = require('incache/index')
// Import way
import incache from 'incache/index'
I'd like to use this as purely in memory storage, with nothing saved to disk.
I get this error when I don't specify a physical file to store the cache in.
"ENOENT: no such file or directory, open '.incache'"
The library really should be able to function without actually specifying a file. When one is not specified, should fall back to memory only usage.
Hi,
I saw that the library exposes only a flag called save
which defines if we want to save the current memory stack to a file in the disk. This is very useful, although the loading part feels a little bit undocumented and also is not really clear how to know when the memory is ready after load.
Therefore I purpose a little change that will greatly improve the overall development experience with this library. What we need to do are basically two things:
autoload
and autosave
, which will provide transparency on which of the two ( or both ) actions do we need. An example will be:const storage = new InCache({
// Provide an autoloading mechanism in the constructor
autoload: true,
// Basically is the `save` flag, with a more transparent naming
autosave: true
})
.load()
and .save()
. These two methods, will obviously take care of loading and saving the internal memory. They must always return a Promise, and always resolve depending on the auto
flag relatively set. An example would be:const load = () => {
return new Promise(
( resolve, reject ) => {
if ( opts.autoload ) {
// load the file from memory and resolve when done, reject if any error occours
} else
resolve()
}
)
}
Same applies for .save()
If you have any question feel free to reach me on this issue anytime.
Thank you in advance,
Julian
Hey,
I need to share data between parent and child nodes. I'm wondering whether I can use inCache for my purpose. I tried to do it, but unfortunately, the child process is not being able to read the stored object.
So, does the feature to share objects between processes is implemented or not?
const storage = new InCache({
autoSave: true
})
If node process will be restarted we lost all data stored in cache.
This is not a problem in most of condition but there are few scenarios where this could be a problem, for example if you store information about sessions during a restart you probably get unverified session.
Is it possible to add an option that store data in a file ?
hi, I have an issue while saving.. the cache is saved in ANSII encoding. Is there a way to force UTF8?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.