|
| 1 | +# @summary |
| 2 | +# Installs and configures `mod_cache_disk`. |
| 3 | +# |
| 4 | +# @description |
| 5 | +# This will install an configure the proper module depending on the used apache version, so |
| 6 | +# - mod_cache_disk for apache version >= 2.4 |
| 7 | +# - mod_disk_cache for older apache versions |
| 8 | +# |
| 9 | +# @param cache_root |
| 10 | +# Defines the name of the directory on the disk to contain cache files. |
| 11 | +# Default depends on the Apache version and operating system: |
| 12 | +# - Debian: /var/cache/apache2/mod_cache_disk |
| 13 | +# - FreeBSD: /var/cache/mod_cache_disk |
| 14 | +# - Red Hat, Apache 2.4: /var/cache/httpd/proxy |
| 15 | +# - Red Hat, Apache 2.2: /var/cache/mod_proxy |
| 16 | +# |
| 17 | +# @param cache_enable |
| 18 | +# Defines an array of directories to cache, the default is none |
| 19 | +# |
| 20 | +# @param cache_ignore_headers |
| 21 | +# Specifies HTTP header(s) that should not be stored in the cache. |
| 22 | +# |
| 23 | +# @param cache_dir_length |
| 24 | +# The number of characters in subdirectory names |
| 25 | +# |
| 26 | +# @param cache_dir_levels |
| 27 | +# The number of levels of subdirectories in the cache. |
| 28 | +# |
| 29 | +# @param cache_default_expire |
| 30 | +# The default duration to cache a document when no expiry date is specified. |
| 31 | +# |
| 32 | +# @param cache_max_expire |
| 33 | +# The maximum time in seconds to cache a document |
| 34 | +# |
| 35 | +# @param cache_ignore_no_lastmod |
| 36 | +# Ignore the fact that a response has no Last Modified header. |
| 37 | +# |
| 38 | +# @param cache_header |
| 39 | +# Add an X-Cache header to the response. |
| 40 | +# |
| 41 | +# @param cache_lock |
| 42 | +# Enable the thundering herd lock. |
| 43 | +# |
| 44 | +# @param cache_ignore_cache_control |
| 45 | +# Ignore request to not serve cached content to client |
| 46 | +# |
| 47 | +# @param cache_max_filesize |
| 48 | +# The maximum size (in bytes) of a document to be placed in the cache |
| 49 | +# |
| 50 | +# @note |
| 51 | +# Apache 2.2, mod_disk_cache installed. On Apache 2.4, mod_cache_disk installed. |
| 52 | +# |
| 53 | +# @see https://httpd.apache.org/docs/2.2/mod/mod_disk_cache.html for additional documentation on version 2.2. |
| 54 | +# |
| 55 | +# @see https://httpd.apache.org/docs/2.4/mod/mod_cache_disk.html for additional documentation on version 2.4. |
| 56 | +# |
| 57 | +class apache::mod::cache_disk ( |
| 58 | + $cache_root = undef, |
| 59 | + Array[String] $cache_enable = [], |
| 60 | + Optional[String] $cache_ignore_headers = undef, |
| 61 | + Optional[Integer] $cache_dir_length = undef, |
| 62 | + Optional[Integer] $cache_dir_levels = undef, |
| 63 | + Optional[Integer] $cache_default_expire = undef, |
| 64 | + Optional[Integer] $cache_max_expire = undef, |
| 65 | + Optional[Enum['Off', 'On']] $cache_ignore_no_lastmod = undef, |
| 66 | + Optional[Enum['off', 'on']] $cache_header = undef, |
| 67 | + Optional[Enum['off', 'on']] $cache_lock = undef, |
| 68 | + Optional[Enum['Off', 'On']] $cache_ignore_cache_control = undef, |
| 69 | + Optional[Integer] $cache_max_filesize = undef, |
| 70 | +) { |
| 71 | + include apache |
| 72 | + if $cache_root { |
| 73 | + $_cache_root = $cache_root |
| 74 | + } |
| 75 | + elsif versioncmp($apache::apache_version, '2.4') >= 0 { |
| 76 | + $_module_name = 'cache_disk' |
| 77 | + $_cache_root = $::osfamily ? { |
| 78 | + 'debian' => '/var/cache/apache2/mod_cache_disk', |
| 79 | + 'redhat' => '/var/cache/httpd/proxy', |
| 80 | + 'freebsd' => '/var/cache/mod_cache_disk', |
| 81 | + } |
| 82 | + } |
| 83 | + else { |
| 84 | + $_module_name = 'disk_cache' |
| 85 | + $_cache_root = $::osfamily ? { |
| 86 | + 'debian' => '/var/cache/apache2/mod_disk_cache', |
| 87 | + 'redhat' => '/var/cache/mod_proxy', |
| 88 | + 'freebsd' => '/var/cache/mod_disk_cache', |
| 89 | + } |
| 90 | + } |
| 91 | + $_configuration_file_name = "${_module_name}.conf" |
| 92 | + $_class_name = "::apache::mod::${_module_name}" |
| 93 | + |
| 94 | + apache::mod { $_module_name: } |
| 95 | + |
| 96 | + Class['::apache::mod::cache'] -> Class[$_class_name] |
| 97 | + |
| 98 | + # Template uses |
| 99 | + # - $_cache_root |
| 100 | + # - $cache_enable |
| 101 | + # - $cache_dir_length |
| 102 | + # - $cache_ignore_headers |
| 103 | + # - $cache_dir_length |
| 104 | + # - $cache_dir_levels |
| 105 | + # - $cache_default_expire |
| 106 | + # - $cache_max_expire |
| 107 | + # - $cache_ignore_no_lastmod |
| 108 | + # - $cache_header |
| 109 | + # - $cache_lock |
| 110 | + # - $cache_ignore_cache_control |
| 111 | + # - $cache_max_filesize |
| 112 | + file { $_configuration_file_name: |
| 113 | + ensure => file, |
| 114 | + path => "${apache::mod_dir}/${_configuration_file_name}", |
| 115 | + mode => $apache::file_mode, |
| 116 | + content => template('apache/mod/cache_disk.conf.erb'), |
| 117 | + require => Exec["mkdir ${apache::mod_dir}"], |
| 118 | + before => File[$apache::mod_dir], |
| 119 | + notify => Class['apache::service'], |
| 120 | + } |
| 121 | +} |
0 commit comments