• Resolved JProffitt3G

    (@jproffitt3g)


    I noticed that this gets cached along with everything else and ends up displaying an out-of-date time. On some sites I cannot disable the cache and need to display hours in either a sidebar or in the header, which appear on most/all pages.

    I’m wondering if there is a way to get around this without complicating the view. I think it can be done with javascript.

    I think the easiest way to do this would be to create AJAX endpoints that simply take the shortcode attributes and returns the output of the respective shortcode, and then add the original attributes to the template in a data attribute. On page load a script would grab all of these and make requests using the data attribute to get the latest hours.

    If you hid this behind a global feature checkbox like “Make Cache-Friendly” that defaults to off I think everyone would be happy.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Wombat Plugins

    (@maartenbelmans)

    I’ve been thinking about this yesterday as well. The main question I asked myself is if caching is a concern for my plugin, or for the user with the 3rd party caching software.

    For example, I think WP Super Cache allows to define parts that shouldn’t be cached. So the end user could theoretically manage it.

    I’ll probably end up including something to battle caching, because aside from caching plugins, there are also CDN’s and the like. Chances are a normal site owner doesn’t know how to configure everything properly.

    I’m just not a big fan of using Ajax when it’s not necessary, so I’m hoping for a better way – just not sure what that is yet ??

    Thread Starter JProffitt3G

    (@jproffitt3g)

    I understand, it is hard to justify adding complexity when the plugin already fulfills its function perfectly on a core install. However I think this is an exceptional circumstance where it is justified.

    This is basically an issue of cache-invalidation, saying part of the page needs to be refreshed, and that is a very hard (if not impossible) problem to solve from the top-down. WP Super Cache does not do it to my satisfaction.

    Cache-invalidation on WordPress is even harder because of its architecture. Everything on a given page is generated as part of a monolithic view, with one entry point at the very beginning and no hooks for a third party to know what rendered what on the page and what changed since last time. Therefore the only way to get a new version of part of the page is to rerender the whole page.

    However lets say you could rerender just the part you needed. Then theres still the issue of how to merge that into / compose it with the existing cached page. Do you perform complex string manipulation on the server side? Do you defer it to javascript and do a jQuery(‘…’).replace()? Something else? Both of those have drawbacks and may not work in a lot of cases.

    Once you solve that problem, there is still a more fundamental issue with this whole approach to caching, and thats that it requires spinning up PHP to coordinate (even if the cached page is fine as is). In my case PHP is the slowest component, adding 0.5s to 1s to page load time (its using SuPHP, and I cannot yet move to PHP-FPM). Most of the savings I get from caching come from avoiding hitting PHP in the first place.

    So cache-invalidation has to happen from the bottom-up (I should say “cache-invaldation” with air-quotes because my point is basically we have no way to do it at all on WordPress). Every developer has to write their own solution to make their particular plugin display the latest information in the most seamless way possible. Your plugin would be very easy to do that for, since its views are encapsulated and parameterized, and just need to be exposed via AJAX.

    Hiding it behind a feature checkbox would allow people to use it when they need it, and disable it when they don’t care about the caching and don’t want the javascript overhead.

    • This reply was modified 8 years, 5 months ago by JProffitt3G.

    This caching feature really is a must for the time to work. I’ve had a client who would otherwise love this plugin, but the fact that the website says one thing and the mobile site says another (and it is a day out of date) isn’t acceptable for a restaurant. The plugin really needs to be able to display the correct time, all the time, or it isn’t doing its job. The method JProffitt3G describes sound viable. Would this only be for the pro version?

    Thread Starter JProffitt3G

    (@jproffitt3g)

    I think this is a general enough problem that there might be a way to solve it using a separate plugin. All you need to do is make an ajax backend that can render html / shortcodes securely, and a shortcode that generates calls to that backend. The main issue would be ensuring the backend was secure against malicious input and the frontend didn’t expose sensitive data. When I have time, I’ll investigate that.

    Plugin Author Wombat Plugins

    (@maartenbelmans)

    @jproffitt3g and @kdcpelt,

    The pro now has a feature-checkbox to bypass caching :-).

    How it works: if enabled, the frontend makes an Ajax call with plain javascript. I’m adding a timestamp to the ajax URL so it’s always unique and won’t be cached.

    I know it’s been a long time since this thread was opened, but if you’re still interested it’s there :).

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Aw, don’t go resurrecting a 6 month old topic. ??

    That’s just not good forum etiquette and if people are interested in that feature in the non-pro version they’ll post.

    “Pro” feature discussion just are not for these forums. Anyone looking for a “pro” conversation can contact the author on their site.

    https://businesshourplugin.maartenbelmans.com/

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Feature Request: Make Cache Friendly’ is closed to new replies.