PiranhaCMS / piranha.core

Piranha CMS is the friendly editor-focused CMS for .NET that can be used both as an integrated CMS or as a headless API.
http://piranhacms.org
MIT License
1.97k stars 555 forks source link

Caching breaks ContentService #2041

Closed andyjwwhite closed 5 months ago

andyjwwhite commented 8 months ago

Hi,

When caching is enabled, ContentService caches objects of different types under the same key. This means that once an object is cached, any further calls for the same ID that use a different type will always return null.

This means that using GenericContent objects is impossible with caching enabled. As soon as the list in the manager retrieves a list of ContentInfo objects, all your calls to retrieve the full objects start to fail (and vice versa).

// Get an instance of MyContent
var content = await api.Content.GetByIdAsync<MyContent>(ID);

// This call will now return null until cache is cleared
var contentInfo = await api.Content.GetByIdAsync<ContentInfo>(ID);
tidyui commented 5 months ago

Fixed by @cktricky