i just wondering
what is the best practice to store value
cache in file system Or in memory In terms of performance
i don't want use Redis cache or any software
just want to used either (memory cache OR file cache) to cache so file for period of time
CodePudding user response:
Redis, memcache, memcached are just wrappers or helpers to access memory blocks (so you dont have to map memory blocks manually)
That being said, and to answer your question it depends on the OS you are using, assuming you are running linux, by default when you open a file it makes uses of the kernel filesystem_cache, you could make use of that and just use file cache, for most applications this is the best as it is reliable even on memory dumps or system reboots.
memory cache is the fastest, and the best for concurrency, but is not to be rely on.
lets look at it with an example if your application makes 100 calls/second
when the request is not cached, it takes 10 seconds to generate/serve the request
it means you need to support to have open 1000 threads for the 10 seconds the request will take, besides that you will be processing the same cache 1000 times. unless you can set a flag to let other process know that you are already generating that data and to just wait.
based on this scenario you could have a process that generates that file each day.
if you use file cache, you will be safe if the systems dumps memory or anything because you're file will still exist.
if you use memory cache, you will be in troubles as you will to generate the file either on the fly or manually, either way you have a downtime of at least 10 seconds.
it's just an example, your flow could be completely different.
comment if you have any doubt ill try to expand (: