Dear Perl Monks,

I am trying to figure out how I can do server-side caching of dynamic webpages that Mojolicious generates in response to webrequests. So that, expensive processing (e.g. on data pulled from a database) done on regenerating the same webpages again is bypassed for subsequent webrequests.

I was looking for a file-based caching solution for Mojolicious, something like what this module does, but unfortunately the module seems outdated and does not install: Mojolicious::Plugin::Cache. In CGI, such a solution is implemented in CGI::Buffer, and Cache::Cache.

I found caching support in Mojolicious, but this appears to be client-side caching, as shown below:

helper 'cache_control.five_minutes' => sub ($c) { $c->res->headers->ca +che_control('public, max-age=300') }; get '/some_older_story' => sub ($c) { $c->cache_control->five_minutes; $c->render(text => 'This one can be cached for a bit.'); }; #ref: https://metacpan.org/pod/distribution/Mojolicious/lib/Mojoliciou +s/Guides/Rendering.pod

I also tried to use statements as below, but this does not seem to work for me, maybe I am missing something here.

use Mojolicious::Lite app->renderer->cache->max_keys(100);

Please advise how to go about.

Thank you very much!


In reply to Server-side caching of webpages in Mojolicious by rajaman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.