Skip to content

Commit

Permalink
Clear SiteSettings Cache after the update (#16068)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored May 16, 2024
1 parent 3418d2d commit f424722
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,32 @@ public SiteService(IDocumentManager<SiteSettings> documentManager, IClock clock)
/// Loads the site settings from the store for updating and that should not be cached.
/// </summary>
// Await as we can't cast 'Task<SiteSettings>' to 'Task<ISite>'.
public async Task<ISite> LoadSiteSettingsAsync() => await _documentManager.GetOrCreateMutableAsync(GetDefaultSettingsAsync);
public async Task<ISite> LoadSiteSettingsAsync()
=> await _documentManager.GetOrCreateMutableAsync(GetDefaultSettingsAsync);

/// <summary>
/// Gets the site settings from the cache for sharing and that should not be updated.
/// </summary>
// Await as we can't cast 'Task<SiteSettings>' to 'Task<ISite>'.
public async Task<ISite> GetSiteSettingsAsync() => await _documentManager.GetOrCreateImmutableAsync(GetDefaultSettingsAsync);
public async Task<ISite> GetSiteSettingsAsync()
=> await _documentManager.GetOrCreateImmutableAsync(GetDefaultSettingsAsync);

/// <summary>
/// Updates the store with the provided site settings and then updates the cache.
/// </summary>
public Task UpdateSiteSettingsAsync(ISite site) => _documentManager.UpdateAsync(site as SiteSettings);
public async Task UpdateSiteSettingsAsync(ISite site)
{
if (site is not SiteSettings siteSettings)
{
return;
}

await _documentManager.UpdateAsync(siteSettings);

// Clear the internal cache to ensure that any other lookup against
// this document will load the new values until the site is reloaded.
siteSettings.ClearCache();
}

private Task<SiteSettings> GetDefaultSettingsAsync()
{
Expand Down
5 changes: 5 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Settings/SiteSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,10 @@ public class SiteSettings : DocumentEntity, ISite

return settings;
}

internal void ClearCache()
{
_cache.Clear();
}
}
}

0 comments on commit f424722

Please sign in to comment.