logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: FilesMatch
Author
MysteryFalcon



Joined: 01 Dec 2021
Posts: 3
Location: Stockholm

PostPosted: Wed 01 Dec '21 13:00    Post subject: FilesMatch Reply with quote

I would like to turn on cache for specific .jpgs on a website, located in specific directories but I'm a bit uncertain how this would be done.
This is the structure I would like caching to apply to:

<FilesMatch "usr/*/[ALPHANUMERIC].jpg">

Does anyone know how to solve this? Help is much appreciated.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Wed 01 Dec '21 17:13    Post subject: Reply with quote

That is a regex

Code:
usr\/(.*)\/\w+\.(jpe?g)$


See https://regexper.com/#usr%5C%2F%28.*%29%5C%2F%5Cw%2B%5C.%28jpe%3Fg%29%24
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 348
Location: UK

PostPosted: Wed 01 Dec '21 17:34    Post subject: Reply with quote

Rather than get into the complexity of setting up and managing server side cache resources (memory or disk), I've previously passed this requirement over to the client browser, to prevent repeat requests for the same static files.

In the global section of your configuration file put something like:
Code:
# Set cache control environment variables for selected file request types.
# These variables are used to conditionally set cache-control headers.
#
RewriteCond %{REQUEST_URI} (?i)\.(css|js)$
RewriteRule .* - [E=ShortCache:true,NE]

RewriteCond %{REQUEST_URI} (?i)\.(gif|jpg|jpeg|png)$
RewriteRule .* - [E=LongCache:true,NE]

RewriteCond %{REQUEST_URI} (?i)\.app$
RewriteRule .* - [E=NoCache:true,NE]

and then further down (global or vhosts) add the following (adjusting max-age to suit):
Code:
# Set cache control header for selected file types, with an expiry time of 2 hours
# for script files, 24 hours for image files, and no cache for application files.
#
Header set Cache-Control "max-age=7200" env=ShortCache
Header set Cache-Control "max-age=86400" env=LongCache
Header set Cache-Control "no-cache, no-store, must-revalidate" env=NoCache
Header set Pragma "no-cache" env=NoCache

Accepting this strategy does rather depend on your site content and function, but in the past I've found this approach make a signficant difference to server throughput.
Back to top
MysteryFalcon



Joined: 01 Dec 2021
Posts: 3
Location: Stockholm

PostPosted: Thu 02 Dec '21 16:36    Post subject: Reply with quote

Many thanks for the help!!
Back to top


Reply to topic   Topic: FilesMatch View previous topic :: View next topic
Post new topic   Forum Index -> Apache