gocache icon indicating copy to clipboard operation
gocache copied to clipboard

ChainCache returns default value with no caches configured

Open pgcamus opened this issue 9 months ago • 1 comments

Our application has configuration options to set up the caching hierarchy. If none of them are configured, we end up with a ChainCache with no stores configured. When this happens, Get() returns a default-constructed value type rather than an error. For example, ChainCache[[]byte].Get() returns a 0-length []byte.

Steps for Reproduction

  1. Configure a ChainCache[[]byte] with no stores.
  2. Call cache.Get() and observe the result coming back

Expected behavior:

Get() returns an error of some sort.

Actual behavior:

Get() returns a default-constructed value which looks like a cache hit, but is really malformed data.

Versions:

lib/v4 v4.2.0

pgcamus avatar Mar 20 '25 14:03 pgcamus

Hi @pgcamus,

Thank you for this feedback.

Please feel free to open a pull request to return an error when no cache is given.

eko avatar Sep 03 '25 19:09 eko