Database cache implementation and generic sort of the cache