Dictionary cache regression

Hi all,

Does anyone know if anything has changed recently with the dictionary cache logic?
We upgraded a few websites to the latest v13.10.1 and since deployment noticed a lot of database hits, after looking into it, appears to be the dictionary queries.

My understanding was, if a dictionary item key was not in the cache it would query the db and then store that response in a cache is this not the case? As we certainly was not seeing this level of reads previously but it’s proving hard to debug at the moment so thought I’d ask here as well.

image

Any advice would be appreciated.

Ta

Jamie

It seems to have happened at some point after 13.7.0

Running the following code on 13.10.1

    for (var i = 0; i < 5; i++) { var b = Umbraco.GetDictionaryValueOrDefault("missing.keys", "whatever"); }

returns

Doing the same in 13.7.0 returns this, a single db hit

I used a bit of AI to research what could have changed and this is what it came up with, sounds plausible:

What the code did before

  • CultureDictionaryFactory would look up dictionary values and cache both hits and misses.
  • That means:
    • If a key existed, its value was cached in-memory.
    • If a key didn’t exist, a “negative cache” entry (e.g. null/empty) was stored so repeated lookups wouldn’t hit the database again.

What changed (the regression)

In 13.10, Umbraco switched its internal caching to use HybridCache (wrapping MemoryCache).
During this refactor:

  • The “negative caching” logic for missing keys was dropped.
  • The GetDictionaryValueOrDefault method now only caches found values.
  • When you call it with a missing or newly-created key, the lookup always hits the database (and may not refresh correctly until the cache is explicitly invalidated).

I would recommend you create an issue for this.

Thanks, issue in progress.

Looks like Callum did this feature in

and then regressed here

Issue created

1 Like

Fixed in Caching: Fixes regression of the caching of null representations for missing dictionary items (closes #20336 for 13) by AndyButland · Pull Request #20344 · umbraco/Umbraco-CMS · GitHub

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.