Replies: 1 comment
-
While I understand the question and suggestion you pose here it is in my opinion better to solve this in another layer. What you are describing is one of the common uses for proxies / loadbalancers where such static data can remain cached. Thus you would not see multiple requests for the same asset as long as the proxy / loadbalancer keeps the asset in its cache. At Another thing to consider is that the static renderer in Mojolicious is pretty decent at being efficient in lookup, retrieval and rendering of static assets. So depending on implementation you might not even gain that much (or anything for that matter) by keeping the asset in memory. Also consider that for applications that can run with thousands of worker processes this can reserve a significant chunk of memory. If you do decide to investigate this further then it would be good to see this functionality created as a plugin, complete with tests and especially important proper benchmarks showing the actual measurable effect. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have some images for my website that will be very often displayed.
<img .. src="global.png" .. >
Has the mojolicious web server a cache system (or anything else) that does useless to load the image "one time for all" at the start of the mojolicious application, (something that would be like
#!/usr/bin/env perl
..
my (%img);
load_img(%img);
..
get ..
get '/routeforimages' => sub {
..
$c->render(data => $img{..}, format => 'png');
}
....
app->start;
..
<img i.. src="/routeforimages?key=<%= $key %>" .. >
..
with
sub load_img($) {
my $rimg = shift;
..
open FILE, './public/global.png';
binmode FILE;
my ($buf, $data, $n);
while (($n = read FILE, $data, 1024) != 0) { $buf .= $data }
close(FILE);
$rimg->{'global'} = $buf;
..
)
Thanks
Beta Was this translation helpful? Give feedback.
All reactions