Clearing Specific Resource from Cache - 2.6.5 - core/cache/db/objects/modResource

I am attempting to keep two instances of MODX synchronized. I am on MODX 2.6.5 and was curious if anyone had any code snippets that would be useful in clearing the cache of a specific resource that has been identified by it’s ID. Instead of clearing the entire cache on each instance everytime a resource is updated, I wanted to just clear the cache for one resource. I’ve found several articles related to doing this, but they do not appear to apply to version 2.6.5. The resource cache now appears to be found here (core/cache/db/objects/modResource) instead of here (/core/cache/resource/web/resources/).

Any help would be appreciated. Thank you!

Sounds like you have cache_db enabled; I’ve never needed that level of caching myself. I’d suggest disabling that setting unless you have a strong reason to use it.

The modCacheManager has some utilities for dealing with the cache. The refresh() method is typically used, but only lets you specify that you want the entire resource section removed. It does however have a delete() method as well, which you can use to target a specific entry. One caveat: that doesn’t work with certain cache provides like memcache, only with file caching.

https://docs.modx.org/current/en/extending-modx/caching#programmatic-custom-caching

It’s not its main purpose, but the CacheMaster extra will clear only the cache of a resource that’s being saved in the Manager. So you could edit the resource, make a minor change like adding a space, then deleting it. When it’s saved the MODX cache will be cleared for just that resource.

This assumes that you’ve disabled cache_db as Mark suggests.

Thank you Mark and Bobray. This was useful.