We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    What I'm trying to do seems like it should be simple. It's for the StageCoach extra, which creates a staged resource, the fields of which are used to update the fields of the original resource at a certain date and time. The first person to visit the page after that time should see the new content.

    So, I want to update the fields of a document during the request process before it's parsed.

    Everything works fine if the target document is not cached or if its cached version has not been created yet.

    If the cached version exists, I can replace the fields of $modx->resource in OnLoadWebDocument, save the resource with the cacheFlag set, physically delete the cache file, refresh or remove the cached version or refresh the whole site cache, but MODX still shows the old version of the resource and the cache is not updated.

    It appears that the resource is in memory (in some place other than $modx->resource) and that version is used to refresh both the cache and $modx->resource after my code executes. The cached, obsolete version is then retrieved, parsed, and displayed.

    I've updated the DB, and cleared the cache for the Resource so is there some way to modify or invalidate the version of the Resource that's in memory?

    I may be able to do everything in OnWebPageInit, but it will slow down the site because I'll have to retrieve the resource and check a TV value for every page load rather then just using $modx->resource (which isn't complete at that point).

    I could also do my updates later in the process, but then the second person to visit the page would see the updates rather than the first.

    This question has been answered by BobRay. See the first response.

      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 38290
      • 712 Posts
      I came across this post this morning and seems like it could be related
      http://forums.modx.com/thread/83430/friendly-url-for-snippet-getpage-modxcloud#dis-post-460247
        jpdevries
      • discuss.answer
        • 3749
        • 24,544 Posts
        I ended up doing this in OnWebPageInit (not very satisfactory, but the only thing I could get to work):

            $cKey = $originalResource->get('context_key');
            $modx->cacheManager->refresh(
                array(
                   'db' => array(),
                   'auto_publish' => array('contexts' => array($cKey)),
                   'context_settings' => array('contexts' => array($cKey)),
                   'resource' => array('contexts' => array($cKey)),
                )
           );
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting