GithubHelp home page GithubHelp logo

Comments (5)

kovshenin avatar kovshenin commented on August 18, 2024 1

Nice! blogid is just an arbitrary string, there's no standard way, you can really flag a cached entry with any string you like, as long as it can be successfully encoded to an decoded from JSON, it should be ok.

from surge.

kovshenin avatar kovshenin commented on August 18, 2024

@MadtownLems you can use Surge\flag() to set specific flags when a page is being rendered, for example if it's rendered using block-1, block-2 and block-3, you can add those flags to the request, then use Surge\expire() to expire block-1 when it's updated, which would invalidate all pages with that flag.

There are some examples in the existing invalidation routines: https://github.com/kovshenin/surge/blob/main/include/invalidate.php

Hope that helps!

from surge.

MadtownLems avatar MadtownLems commented on August 18, 2024

Hope that helps!

I wish it did 😅

I've taken a look at invalidate.php many times now (as well as https://konstantin.blog/2021/wordpress-cache-invalidation-with-flags/ ) and still have no idea how I might use Surge\flag().

We have Surge network activated on a MultiSite network, and what I'm really trying to do is figure out a way to clear a single subsite's entire cache on certain events.

I've also been looking at /wp-content/cache/surge/flags.json.php and am trying to understand how the flags stored in this file differentiate between sites in the multisite 🤔

Any insights you can provide would be much appreciated. 🙏

from surge.

kovshenin avatar kovshenin commented on August 18, 2024

@MadtownLems here's an example:

// Flag each entry with the current blog id.
add_action( 'template_redirect', function() {
    Surge\flag( sprintf( 'blogid:%d', get_current_blog_id() ) );
} );

// Expire all subsite cache on certain events.
add_action( 'certain_event', function() {
    Surge\expire( sprintf( 'blogid:%d', get_current_blog_id() ) );
} );

from surge.

MadtownLems avatar MadtownLems commented on August 18, 2024

here's an example:

Perfect! Exactly what I was looking for. I had no idea that "blogid:" was a valid flag, as I didn't see it anywhere else in invalidate.php.

Question: Are the available flags some standard thing that I can read about somewhere?

from surge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.