nickpresta/chameleon

Avoid disk caching

clakech opened this issue · 3 comments

Hi,

I would like to not cache on disk, only in memory.

Is this easy to setup ? using header _chameleon-seeded-skip-disk for instance ?

May I add a flag to launch chameleon without disk caching and only in memory cachin --nodiskcaching?

Thanks

Hi @clakech,

It sounds like you want the ability to store all data in memory (which would not survive a restart of Chameleon). If that is the case, read on.

This sounds relatively straightforward to setup. In main.go a DiskCacher gets created and seeded. You could add a flag called cacher (to match the hasher flag) which defaults to the DiskCacher but allows someone to specify a MemoryCacher. A similar option is already implemented for CmdHasher/DefaultHasher.

The DiskCacher is an implementation of the Cacher interface which only requires Get and Put to be implemented. These methods should be relatively simple to implement (perhaps a map[string] CachedResponse), and you can look at parts of the DiskCacher implementation (which uses a map[string] CachedResponse internally. You may be able to move some of that code out into functions and reuse it.

I unfortunately don't have the time to implement this feature at the moment but if you want to try implementing it, I will be able to provide feedback and work with you to get it merged in.

Thx for your answer. I did a straighforward implementation by adding a -memory flag that match my need. clakech@549b471

Since I use openshift I change a few other things (.godir and using HOST env var).

Using the same approach as Hasher but for Cacher would be more extensible for other needs. I may digg into this in a few days.

BTW, thanks for sharing your code, very helpful ;-)

I think that externalize caching in the same way as hashing may be more complex because we need to keep results in memory (hashing does not need it).

If we launch a custom cacher using a command I can't see any way to keep the results in memory.

It is easier to handle this directly inside the go code ;-)