Support » Plugin: Custom Content Shortcode » Naming caches dynamically

  • While I’m hoping I can figure out how to optimize my code so things run faster, I realize that there’s no downside to me using caches to speed things up. My pages will mostly not be updated daily, so if there’s a day lag it’s not the end of the world. I could even make it a week without worrying. What I realized, however, is that many pages on my site use exactly the same code pulled in from an external template file. The only content in most of my pages is a load tag pointing to the external file. Since caches need to be named, I need to name each cache dynamically somehow. My first thought was something like:

    [cache name=cache-[field id] expire='1 day']

    but obviously I can’t do that. So then I thought about passing the id like:

    [pass field=id]
    [cache name=cache-{FIELD} expire='1 day']

    but the page already has two other nested [pass] tags and it doesn’t seem to want to deal with a third.

    So my question is if there is another way to create a unique cache name for these pages?

    Thanks.

    https://wordpress.org/plugins/custom-content-shortcode/

Viewing 1 replies (of 1 total)
  • Thread Starter philipt18

    (@philipt18)

    I think I’ve gotten the second option to work for some of my templates that don’t otherwise use a [pass]. I still don’t have a solution for the more complicated templates that already use multiple passes that don’t seem to want to cooperate. Of course, I can’t be 100% sure that it’s working because I don’t know how to tell what current caches exist (see my other post about managing caches). I’m still interested to see if there is a way to create a dynamic cache name without doing the above since it is giving me trouble. Perhaps the [cache] tag could add a way to create a cache name based on the page/post ID? Something like:

    [cache nameid=country]

    on a page whose ID is 1234 would create a cache called country-1234.

    It would even be good if there was a way to pull in a field for the name (so for example in my country example I could pull in the name of the country instead of the ID). Without being able to see the list of caches this is irrelevant, but if it becomes possible to see the caches at some point, this would be useful.

Viewing 1 replies (of 1 total)
  • The topic ‘Naming caches dynamically’ is closed to new replies.