If you want cache to survive reboots, you need to store all of the state
externally, including any timeout/expiry conditions. One way to do it is to
store the timeout (UTC) times together with the cache entry metadata. So an
entry in your (simplified) cache collection would look like:
```
{
"data": payload,
"metadata": {
"type": "something",
"timeout": "2015-07-15T07:11:23.079Z"
}
You'd need a load and store procedures too for the cache server which would
recover all this and serialize/deserialize data, I guess.
On Tuesday, July 14, 2015 at 2:18:44 PM UTC+2, Ingwie Phoenix wrote:
>
> hey.
>
> I want to implement a cache server that starts empty but can restore
> itself after an exit from a JSON database. The principe of doing that seems
> simple, but there is just one problem: the time-to-live parameter.
>
> How can I best introduce a time-to-live, aka. time till the entry gets
> purged automaticaly, in the best node-ish way? I know that just using a
> setTimeout() would be a bad idea since the server might exit in the
> meantime and the key and its value will just be carried over and not be
> urged at the next run.
>
> Any idea how I could implement this best?
>
> Kind regards, Ingwie.
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/f521dd50-9013-4922-bb5c-8829f516986c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.