When we call ReadStream, it checks if the desired value is in the cache and if not calls readWithRLock, which returns a diskv.siphon. The siphon will write to the cache when it gets an EOF from the file on disk.
If we call ReadStream twice on the same key, we get two siphon objects, both of which will write to the cache when they finish reading. However, the cacheWithLock function does not check if the key it has been told to cache already exists in the cache. If the key already exists, cacheWithLock blithely overwrites it (d.cache[key] = val) and then improperly adds to the cache size (d.cacheSize += valueSize).
This patch makes cacheWithLock blow away any existing cached value before it writes into the cache. Benchmarks show no noticeable difference.
When we call ReadStream, it checks if the desired value is in the cache and if not calls readWithRLock, which returns a diskv.siphon. The siphon will write to the cache when it gets an EOF from the file on disk.
If we call ReadStream twice on the same key, we get two siphon objects, both of which will write to the cache when they finish reading. However, the cacheWithLock function does not check if the key it has been told to cache already exists in the cache. If the key already exists, cacheWithLock blithely overwrites it (
d.cache[key] = val
) and then improperly adds to the cache size (d.cacheSize += valueSize
).This patch makes cacheWithLock blow away any existing cached value before it writes into the cache. Benchmarks show no noticeable difference.
Fixes #40