I'm trying to make score-based PHP memory cache, but I have a problem with the performance (how to count score and delete low score records).
Objectives
I have around 10 million records. And I want to cache only 0.1% of the most frequent records in memory, not on disc.
I would like to set 10,000 cache slots (0.1%) and I would like to keep only the most frequented in these slots.
Attempts / Problems
I tried File based cache and it's very slow.
I tried MySQL and PostgreSQL, but it has too much performance cost with counting score and deleting low score records.
I tried Time based cache, ex. xcache, but because of too much data in my project, it's too much writing. Also there is a problem with deleting lowest score records and with listing all cache slots, because it's "key->value".
I found Redis, but it seems that there isn't any score or something similar.
My question:
What cache method should I use for score based cache?
Note that all these posts are similar but do not contain any usable answers:
Fastest PHP memory cache/hashtable
In-memory cache with LRU expiration