cache: Fixes state corruption and improves overall code of LRU cache

Hopefully whould fix issue #26.