Multiple entries in a single key
Hello there,
is there a way to store multiple entires in a single key? (Like an ETS duplicate_bag)
My use case would be a list that only contains the N most recently added entries while discarding older ones. Is there a way to do this using this library or would you recommend another one/rolling my own solution?
Thank you for your time!
Hello,
The cache support addition of multiple entires per key via prepend or append api. However, it does not really behave as Redis in this cases. It would apply eviction for entire group at once if application has not touched the key for awhile. Same time, the group would grow infinitely.
The duplicate bag is not supported for individual cache segments. I am afraid it would not be even possible to make it because of an overhead during cache I/O operations.
You can implement desired solution using apply function. This function executes you own function within the cache context thus you can maintain list of items and evict old items on write. It would be interesting to play around this and measure performance (what does it cost to copy "lists" between segments). Actually apply is generic implementation of append/prepend. I'd propose you to validate your use-case with apply then we can either create a new data type to cache or extends append/prepends with subset eviction.
BTW, If you solution is classical time-base rolling window then you can simply use append/prepend out of the box together with simple logic of generating multiple key names based on the current time span.
Please let me know what do you think?