Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V15: Refresh caches on load balanced environments #17296

Merged
merged 19 commits into from
Oct 28, 2024

Conversation

nikolajlauridsen
Copy link
Contributor

@nikolajlauridsen nikolajlauridsen commented Oct 17, 2024

This fixes #17263

Separates updating the memory cache and database cache into two separate methods.

This is because when load balancing only the publisher should update the database cache, however, all subscribers must update their memory cache.

The memory cache is updated when:

  • The content/media itself changes
  • The content/media type changes
  • A datatype the content/media type uses changes

This also adds new named options for the documents and media, allowing you to configure the local memory cache duration, the remote cache duration and the seed cache duration for documents and media separately using named options under Umbraco:CMS:Cache:Entry::

  "Umbraco": {
    "CMS": {
      "Cache": {
        "Entry": {
          "Document": {
            "LocalCacheDuration": "2.00:00:00",
            "RemoteCacheDuration": "100.00:00:00",
            "SeedCacheDuration": "200.00:00:00"
          },
          "Media": {
            "LocalCacheDuration": "50.00:00:00",
            "RemoteCacheDuration": "150.00:00:00",
            "SeedCacheDuration": "250.00:00:00"
          }
        }
      },
{...}

@nikolajlauridsen nikolajlauridsen changed the base branch from contrib to release/15.0 October 17, 2024 08:21
@IbrahimMNada
Copy link
Contributor

Hello @nikolajlauridsen just quick question , how will the subscribers know if there is content change ?

only depend on the LocalCacheDuration ?

if yes To be honest I don't think that is enough , I think we must have some sort of inter-communication

pub/sub but since there is no coupling with any providers and some providers does not have pub/sub like sql.

we need some default provider and i think about best bet here is web-hooks between publisher and subscribers

@nikolajlauridsen
Copy link
Contributor Author

Hi @IbrahimMNada the subscribers know about content changes through the IServerMessenger, the default implementation is BatchedDatabaseServerMessenger, but this hasn't changed 😄 The new cache needed to hook into these events 😄

@IbrahimMNada
Copy link
Contributor

IbrahimMNada commented Oct 21, 2024

Hello @nikolajlauridsen ,
Thank you for your response

please excuse my stupid questions here, as I'm only trying to learn/understand. from what I understand

you are utilizing umbracoCacheInstruction table right ?
you will check on it every N time based on Umbraco:CMS:Cache:Entry:LocalCacheDuration
?

so if the "LocalCacheDuration": "00:30:00", it will reset every 30 mins right ?
changes will not be reflected as long as the cache is not passed this time

I only trying to understand , Thanks <3

@nikolajlauridsen
Copy link
Contributor Author

nikolajlauridsen commented Oct 21, 2024

No stupid questions 😉

But no, the LocalCacheDuration property is for the hybrid cache entry options. The LocalCacheDuration specifies for how long the items will be in the local IMemoryCache and the RemoteCacheDuration specifies how long the items will stay in the remote IDistributedCache if configured. This is all part of the hybrid cache from Microsoft, we're just providing an easy way to configure it separately for media and content in the Umbraco settings.

The IServerMessenger is a different thing, explicitly made to facilitate the communication between publisher and subscribers.

Without going into too much detail it relies on the InstructionProcessJob recurring background job and syncs every minute through the umbracoCacheInstruction table in the database 😄

This can be configured with the Global:DatabaseServerMessenger:TimeBetweenSyncOperations configuration key

@bielu
Copy link
Contributor

bielu commented Oct 22, 2024

I don't think it is correct approach, as currently you leak cache implementation into cache refresher, when cache refresher shouldn't be aware of cache implementation, only of exposed api of cache which allows to cache refresh. I guess logic to handle memory part should be built-in into AppCaches not into Cache refreshers, as than even if someone dont use memory cache it will be doing this bit of logic.

…fresh-load-balanced

# Conflicts:
#	src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs
#	src/Umbraco.PublishedCache.HybridCache/Services/MediaCacheService.cs
@bergmania bergmania merged commit d1799ec into release/15.0 Oct 28, 2024
14 of 15 checks passed
@bergmania bergmania deleted the v15/hotfix/refresh-load-balanced branch October 28, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants