We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20031
    • 19 Posts
    Before i start the questions, here are a couple of things to note about the site (i know how to solve that):

    - The pages have no userbased views. (logged-in / not-logged-in)
    - Some pages would need to be refreshed on a certain time.
    - a cache file would need to be cleared if a document is published/unpublished/deleted/undeleted/modified. (plugin)
    - a cache file would need to be cleared if its date has expired.

    Performance

    - Perfomance is 170ms to 350ms per pageload right now. and that is with 1 user... (me)
    - Performance with full page cache would be 11-17 ms.

    The technique 1 - rewrite rule

    (have omitted security explainations)

    1. Apache rewrite

    Check if file exists -> Serve file if true, else, index.php?q=....

    example:
    http://site.com/fragment1/fragment2

    looks after fragment1/fragment2/index.php
    looks after fragment1/fragment2/index.html
    looks after cache/fragment1/fragment2/index.php
    looks after cache/fragment1/fragment2/index.html

    doesnt exist? the normal rewrite rule would apply:
    index.php?q=....

    The technique 2 - Cache files

    if request reaches index.php?q=.... there are 2 different ways i would save the cache.

    as /cache/fragment1/fragment2/index.php (if the resource expires in some way or another)
    as /cache/fragment1/fragment2/index.html (if the resource does not expire)

    This way i could completely avoid to use PHP if the resource allows it and serve it a bit faster / use fewer resources. If the file is PHP there would be a simple check inside that checks current date with the cache files expire date...

    The technique 3 - Save the cache

    Here is where my question comes... (I know how to create directories and save files.)
    But i don't know how to get the full page HTML...

    One technique I have previously used is to use ob_start("save_file"); ....contents.... ob_end_flush();
    ( save_file function, which is called on ob_end_flush would then check if the resource is cachable, if it is expirable, compress / html, save the file and return the contents.. )

    Next time a request would be made, to that resource, the file would be there in compressed form.

    I don't want to modify the core, if I can avoid it.

    So... How do I to get the get the full page HTML?

    The technique 4 - clearing the cache
    To maintain the cache i would add a plugin that clears the specific cache for the resource if applicable.

    I really hope anyone has an answer.

    Thanks in advance.
    Milou [ed. note: MODXsammy last edited this post 15 years, 1 month ago.]
      • 33968
      • 863 Posts
      So... How do I to get the get the full page HTML?
      How about a plugin, firing on OnWebPagePrerender?

      Perhaps this response to a similar thread may help you too. I'm serving up some reasonably heavy custom data and cached (php) page loads are down to ~50ms on MAMP - expecting better on a real server.
        • 20031
        • 19 Posts
        :D oh didn't notice that one. Sweet, thanks!

        This might come in handy for others trying the same:

        $output = &$modx->resource->_output;
        $resourceId = $modx->resource->get('id'); [ed. note: MODXsammy last edited this post 15 years, 1 month ago.]
          • 33968
          • 863 Posts
          Glad to help smiley

          Out of interest, how much quicker is it caching the whole page output like that?
            • 20031
            • 19 Posts
            The disk writing part is very fast. it takes no more than 15ms on my hdd in extreme cases. So if a file is not cached it will in this case add 15ms for the first pageview...

            The checking of the file and the call of the plugin is barely noticable. My guess is below 1ms.

            But the speed of the site when the cache is in place, is just amazing. Going from 300ms to 10 ms on html files and 15-20 ms on the php cache files that maintain themselves is very noticeable.

            Almost finished with the caching solution. Works wonders smiley

            But you have to maintain and create the logic that makes sure that the cache is fresh. For-example i have some offers, that only lasts for a specific amount of time. If it is a resource with an offer, the cached file is index.php instead of index.html before i save the index.php file i have to query the DB to figure out when it expires and add that to the php file, which will then refresh itself if that date is below current date.

            The plugin when a resource is deleted/modified/pub/unpub just deletes the appropriate file (or files).

            But when the above is in place, I really dont see any faster solution. Maybe with memcached in the same manner... [ed. note: MODXsammy last edited this post 15 years, 1 month ago.]
              • 20031
              • 19 Posts
              But it really depends.. if you have resources modified all the time, a partial solution is propably better. But for this site where no front-end user specific content is required. It is rock solid. 98% of the resources are very rarely modified.

              The good thing about this solution is that it still uses the excellent partial page caching modx has in place if for some reason you would need some pages not to be cached like that or even when the full page cache is recreated.

              So if you have enough room on your server for the cache files or ram if memcached then I would definitely recommend something like this. [ed. note: MODXsammy last edited this post 15 years, 1 month ago.]
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: okyanet at Sep 01, 2011, 02:23 PM
                Out of interest, how much quicker is it caching the whole page output like that?
                By caching the generated HTML output and having rewrite rules route to those static HTML files if they are available, you are essentially bypassing MODX, and PHP itself, altogether. You would then have basically the same performance as a regular static HTML page, which will always be much faster than server dynamic PHP generated pages. But you also cannot have any dynamic content without much more complex caching based on header or cookie data.
                  • 20031
                  • 19 Posts
                  Yes, as i said, it depends on the scenario.

                  In my case it is not very difficult to maintain the cache and yes some pages cannot be cached like that.

                  but for pages that can... I would recommend it.