We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6531
    • 154 Posts
    Our site uses the Vimeo PHP library (https://github.com/vimeo/vimeo.php).

    Currently I'm calling the library within snippets, e.g.:

    require_once("____/autoload.php");
    $vimeo = new \Vimeo\Vimeo(____AuthKeys, etc.___);
    ...
    $videos = $vimeo->request('/me/albums/____)['body']['data']
    ...
    


    But this means way more calls to the API than necessary ... right?

    Vimeo recommends caching the response, but I'm not sure how to do that in modx.

    I'm guessing the first 3 lines only need to be run once, then cached ... until we make changes to our Vimeo account (add videos, albums, etc.)

    What's the best way to accomplish this?

    The only part that changes from snippet to snippet is the `$vimeo->request...` portion ... is there a way to only have that at the start of our snippets?
      • 3749
      • 24,544 Posts
      Unless the requests are all made on the same web page, you do need the first two lines. If they are all on the same page, you could put the first two lines in a separate snippet at the top or in the template, unless the request line is repeated in a loop, then you can just put the first two lines outside the loop.

      For caching the response, I think you'd have to create your own cache and write the content of $videos to it (maybe with serialize()). Then for each request, you'd have to check the cache and read (and unserialize()) the data if there's a cache hit, and make the request if not. You can't call the snippet cached because you'd get the wrong videos on many pages.









        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
        • 6531
        • 154 Posts
        Thanks for that ... I think I understand ...

        The caching is simpler than I thought! [ed. note: danzg last edited this post 6 years, 10 months ago.]
          • 3749
          • 24,544 Posts
          I'm glad I could help.

          On second thought, serialize() is not a good choice if you're storing photos or video. It would probably be better to just read and write them as binary data.

          You might also take a look at StatCache, though it has some limitations and might not work for your use case. [ed. note: BobRay last edited this post 6 years, 10 months ago.]
            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