Skip to content

Commit b57883e

Browse files
committed
Added cache_disk
Deprecates disk_cache
1 parent 1756ce0 commit b57883e

File tree

3 files changed

+171
-40
lines changed

3 files changed

+171
-40
lines changed

manifests/mod/cache_disk.pp

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+
}

manifests/mod/disk_cache.pp

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,29 @@
66
# Default depends on the Apache version and operating system:
77
# - Debian: /var/cache/apache2/mod_cache_disk
88
# - FreeBSD: /var/cache/mod_cache_disk
9-
# - Red Hat: /var/cache/httpd/proxy
9+
# - Red Hat, Apache 2.4: /var/cache/httpd/proxy
10+
# - Red Hat, Apache 2.2: /var/cache/mod_proxy
1011
#
1112
# @param cache_ignore_headers
1213
# Specifies HTTP header(s) that should not be stored in the cache.
1314
#
14-
# @param default_cache_enable
15-
# Default value is true, which enables "CacheEnable disk /" in disk_cache.conf for the webserver. This would cache
16-
# every request to apache by default for every vhost. If set to false the default cache all behaviour is supressed.
17-
# You can then control this behaviour in individual vhosts by explicitly defining CacheEnable.
18-
#
1915
# @note
20-
# On Apache 2.4, mod_cache_disk installed.
16+
# Apache 2.2, mod_disk_cache installed. On Apache 2.4, mod_cache_disk installed.
17+
# This class is deprecated, use mode_cache_disk instead
18+
#
19+
# @see https://httpd.apache.org/docs/2.2/mod/mod_disk_cache.html for additional documentation on version 2.2.
2120
#
22-
# @see https://httpd.apache.org/docs/2.4/mod/mod_cache_disk.html for additional documentation.
21+
# @see https://httpd.apache.org/docs/2.4/mod/mod_cache_disk.html for additional documentation on version 2.4.
2322
#
2423
class apache::mod::disk_cache (
25-
Optional[Stdlib::Absolutepath] $cache_root = undef,
26-
Optional[String] $cache_ignore_headers = undef,
27-
Boolean $default_cache_enable = true,
24+
$cache_root = undef,
25+
$cache_ignore_headers = undef,
2826
) {
29-
include apache
30-
if $cache_root {
31-
$_cache_root = $cache_root
32-
} else {
33-
$_cache_root = $facts['os']['family'] ? {
34-
'Debian' => '/var/cache/apache2/mod_cache_disk',
35-
'RedHat' => '/var/cache/httpd/proxy',
36-
'FreeBSD' => '/var/cache/mod_cache_disk',
37-
}
38-
}
39-
40-
apache::mod { 'cache_disk': }
41-
42-
Class['apache::mod::cache'] -> Class['apache::mod::disk_cache']
43-
44-
$parameters = {
45-
'default_cache_enable' => $default_cache_enable,
46-
'_cache_root' => $_cache_root,
47-
'cache_ignore_headers' => $cache_ignore_headers,
48-
}
27+
deprecation('apache::mod::disk_cache','This module is deprecated; please use apache::mod::cache_disk')
4928

50-
# Template uses $_cache_root
51-
file { 'disk_cache.conf':
52-
ensure => file,
53-
path => "${apache::mod_dir}/disk_cache.conf",
54-
mode => $apache::file_mode,
55-
content => epp('apache/mod/disk_cache.conf.epp', $parameters),
56-
require => Exec["mkdir ${apache::mod_dir}"],
57-
before => File[$apache::mod_dir],
58-
notify => Class['apache::service'],
29+
class { 'apache::mod::cache_disk':
30+
cache_root => $cache_root,
31+
cache_enable => ['/'],
32+
cache_ignore_headers => $cache_ignore_headers,
5933
}
6034
}

templates/mod/cache_disk.conf.erb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
CacheRoot "<%= @_cache_root %>"
2+
<%- if @cache_enable -%>
3+
<%- @cache_enable.each do |enable| -%>
4+
CacheEnable disk <%= enable %>
5+
<%- end -%>
6+
<%- end -%>
7+
<%- if @cache_dir_length -%>
8+
CacheDirLength <%= @cache_dir_length %>
9+
<%- end -%>
10+
<%- if @cache_dir_levels -%>
11+
CacheDirLevels <%= @cache_dir_levels %>
12+
<%- end -%>
13+
<%- if @cache_default_expire -%>
14+
CacheDefaultExpire <%= @cache_default_expire %>
15+
<%- end -%>
16+
<%- if @cache_max_expire -%>
17+
CacheMaxExpire <%= @cache_max_expire %>
18+
<%- end -%>
19+
<%- if @cache_ignore_no_lastmod -%>
20+
CacheIgnoreNoLastMod <%= @cache_ignore_no_lastmod %>
21+
<%- end -%>
22+
<%- if @cache_header -%>
23+
CacheHeader <%= @cache_header %>
24+
<%- end -%>
25+
<%- if @cache_lock -%>
26+
CacheLock <%= @cache_lock %>
27+
<%- end -%>
28+
<%- if @cache_ignore_cache_control -%>
29+
CacheIgnoreCacheControl <%= @cache_ignore_cache_control %>
30+
<%- end -%>
31+
<%- if @cache_max_filesize -%>
32+
CacheMaxFileSize <%= @cache_max_filesize %>
33+
<%- end -%>
34+
<%- if @cache_ignore_headers -%>
35+
CacheIgnoreHeaders <%= @cache_ignore_headers -%>
36+
<%- end -%>

0 commit comments

Comments
 (0)