sasa1977 / con_cache

ets based key/value cache with row level isolated writes and ttl support
MIT License
910 stars 71 forks source link

Support to ets table types #25

Closed fcevado closed 8 years ago

fcevado commented 8 years ago

I've tried to start a :bag table, but when I retrieved the data only returned the last value inserted. There is any plan on support other type of tables then :set?

sasa1977 commented 8 years ago

Hi,

Way back when I implemented con_cache, I only needed it for basic key-value operations, so I just handled the set type, meaning that bag tables are not officially supported (see here). I've simply never needed it, and no one else asked for it :-)

I'd need to look at the code a bit, but my first instinct is that it should be possible to support the bag type, and possibly even not too hard (standard disclaimers apply :-) ). However, I can't really commit on any deadline here. So if you're maybe willing to give it a try, a pull request would be welcome :-)

fcevado commented 8 years ago

I'll do it. I'll take a look at the code and try to come with the pr this weekend. :)

sasa1977 commented 8 years ago

Cool! If you have any questions, feel free to ask.

fcevado commented 8 years ago

Hi @sasa1977, I think most of the changes are done. But I don't know what to do with the fun update_existing, should it support both a list(in the case of a bag table) and a single value? I guess it would be useful, but would require major changes on how the update is done.

sasa1977 commented 8 years ago

My first instinct is that such operation doesn't make much sense in a bag type. Looking at Erlang docs for similar operations in ETS, I can see that update_element supports only set (and ordered set) tables, and fails with reason badarg otherwise. So I think that's what we should do with update and update_existing.

fcevado commented 8 years ago

About that, I kinda disagree in some points. I understand the idea to keep faithful to ets principles. But I see a lot of usage for an update_* to bag types, since it's explicit on docs that is entirely the responsability of the user that the values of a given key should be of the same type for update_* to work.

But I think its not the scope of this issue, nor the scope of a single pull request to change that much of the internals of ConCache. First let's make ConCache work in a trustable way with bag types.