All Products
Document Center

Apache cache policy setting

Last Updated: Jan 24, 2019

Apache expiration policies can be set in mod_expires and mod_headers on apache.

  • Setting in mod_expires:

    The contents of the Expires and Cache-Control headers of HTTP can be set using the configuration file.

    mod_expires is mainly used to automatically generate the Expires label and Cache-Control label in the page header information, thus decreasing the client access frequency and times, reducing unnecessary traffic and increasing access speed.

    Among various modules of Apache, the configuration of mod_expires is relatively simple. mod_expires has only three commands.

    ExpiresActive command: Enables or disables the function of generating the “Expires:” and “Cache-Control:” headers.

    ExpiresByType command: Specifies the expiration time for MIME files (e.g. text/HTML).

    ExpiresDefault command: Sets the default expiration time for all files.

    Representation of expiration time

    • ccess plus 1 month”

    • ccess plus 4 weeks”

    • ow plus 30 days”

    • odification plus 5 hours 3 minutes”

    • 592000

    • M604800

    access, now, and A have the same meaning that the expiration time is counted from the time of access.

    modification and M have the same meaning that the expiration time is counted from the last modification time of the accessed file.

    Therefore, modification and M take effect only for static files, but not for the dynamic pages generated from scripts.

    Configuration example:

    • ExpiresActive On (Enable mod_expires.)

    • ExpiresDefault “access plus 6 months” (The default expiration time is 6 months.)

    • ExpiresByType image/ “access plus 10 years” (The cache time for image files is 10 years.)

    • ExpiresByType text/ “access plus 10 years” (The cache time for text files is 10 years.)

    • ExpiresByType application/ “access plus 30 minutes” (The cache time for application files is 30 minutes.)

    Verify that the cache time for image/JPEG files is 315,360,000s (10 years). pic1

    The following command is used to set image/JPEG files to no-cache (max-age: 0s):

    #ExpiresByType image/ “access plus 10 years”

    ExpiresByType image/* A0


  • Configuration using mod_headers:

    • # YEAR

      Header set Cache-Control “max-age=2592000″

    • # WEEK

      Header set Cache-Control “max-age=604800″


      • Header set Expires “Thu, 01 Dec 2003 16:00:00 UTC”

      • Header set Cache-Control “no-store, no-cache, must-revalidate”

      • Header set Pragma “no-cache”