Is there a technology that can cache an ordered list and retrieve sorted results from arbitrary points in the ordering?
Imagine a timeline like a Twitter stream, where you want to quickly return a result for all items after date n. Is there a caching technology like Memcache that can cache this data in a way that can be queried in order, dropping older items to make room for new data?
I would imagine the interface would work like the following:
Adding items would always add to the head of the list.
Cache.add(key, timestamp, data)
Items could be queried given a timestamp.
Cache.getAfter(key, timestamp)
The .get() function would be guaranteed to not return items older than the given timestamp, and would return items starting from the开发者_运维知识库 head of the list ordered oldest to newest.
When the cache needs to evict items, items with the oldest timestamps are removed first.
It looks like a Redis list is the best solution.
With the LPUSH and LTRIM commands, you can easily make a list that does not grow larger than N items.
LPUSH mylist someelement
LTRIM mylist 0 99
精彩评论