Your structure is efficient enough for caching, but I would not use it in a place critical for performance. If your cache grows and you have 5,000 items in one place, you are still doing a linear search on 5,000 items.
I think it's better to sort the list and use binary search to find items in the cache.
If I implemented something like this, I would take a TList with pointers to records. A list to be sorted with TList.Sort, which I provide to sort the list according to the data containing the records. Sorting will be performed in the field with the highest "selectivity", then in the fields with the second higher selectivity, etc.
If you want to find a record, you perform a binary search in the list and get the value, if it does not exist, you get it from the database and add it to the cache.
Of course, all this would be beautifully wrapped in a class that takes care of this and memory allocation problems.
A hash file is also possible, but you need to do tests to find out which is faster.
source share