6 ms·
While caches and maps share many of the same underlying properties, they serve very different purposes. Caches generally come with configurable size limits, evi
by meritt 7y ago
While caches and maps share many of the same underlying properties, they serve very different purposes. Caches generally come with configurable size limits, eviction policies, and collision handling (overwriting is a simple solution). They are in no way designed to be durable data storage mechanisms.
- kbaker 7y agoSo does it just serve completely incorrect data when a request for the 'old' cache key come in? Seems like this would always be undesirable behavior for a cache? It is definitely being advertised as a map-like structure, key goes in, bytes come out...
- archgoon 7y agoHaven't looked at the full implementation of BigCache, but typically, a cache would fetch the object and key from the data structure. If the full key doesn't match the requested key, then the cache will respond that the key is not in the cache. The calling function would then figure out whether to replenish the cache or not. Update: Yes, that appears to be the strategy in shard.go. if entryKey := readKeyFromEntry(wrappedEntry); key != entryKey { s.lock.RUnlock() s.collision() if s.isVerbose { s.logger.Printf("Collision detected. Both %q and %q have the same hash %x", key, entryKey, hashedKey) } return nil, ErrEntryNotFound } so there is no risk of returning the wrong data for a key.
- kbaker 7y agoAh OK, that's good, just was reading too much into this section in the README: > BigCache does not handle collisions. When new item is inserted and it's hash collides with previously stored item, new item overwrites previously stored value.