Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for caching #14

Open
notslang opened this issue Mar 24, 2014 · 8 comments
Open

support for caching #14

notslang opened this issue Mar 24, 2014 · 8 comments
Labels

Comments

@notslang
Copy link
Contributor

Some compilers (like HAML) already do this, but it would be nice to have a universal caching mechanism. Thoughts?

@jescalan
Copy link
Owner

Hmm, I don't know a ton about it, but I would be interested. Any ideas on potential implementation?

@notslang
Copy link
Contributor Author

It's pretty simple, you hash the options & input string, that becomes the key in an object, and then the value for that key is the result of compiling the input string with those options.

So the cache object could look something like this:

{
    "vTFzjmJEH3MBFEspWxmmHhsQPpuir3": "<h1>Hello World!</h1>"
}

*that's not a real hash btw, I just smashed my keyboard a bit till it looked kinda like one

@jescalan
Copy link
Owner

Gotchya, makes sense. Interested in taking a stab at the initial PR for this?

@notslang
Copy link
Contributor Author

Actually, I was totally wrong about needing a hash - JS has no limit for keysize so long as it fits in memory, because the key is just a pointer to a regular string in memory... nothing special.

But anyway, I'm thinking of using LevelUP for a persistent cache, shared between processes. Thoughts?

@jescalan
Copy link
Owner

This would have to be in a separate library I assume, and would require the user to also install leveldb?

@notslang
Copy link
Contributor Author

I don't think so - it could be in a separate lib if you want, but caching is a pretty basic feature that should be beneficial like 99% of the time. As for installing leveldb: that can be done automatically via npm, if I'm not mistaken.

@jescalan
Copy link
Owner

Ok, I'm fine with this as long as it doesn't add any external dependencies and as long as leveldb brings any sort of speed or interface advantage to the cacheing over just using an object.

@notslang
Copy link
Contributor Author

yep - the interface advantage is that an object can only be used in a single process, during the lifetime of that process. leveldb could be caching compiled files for days, with the cache still being accessible when you restart the process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants