Skip to content

Commit 958023b

Browse files
authored
Merge pull request #2142 from Pawa2NR/disk_cache
The default disk_cache.conf.erb caches everything.
2 parents 686a147 + b4ede7a commit 958023b

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed

manifests/mod/disk_cache.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
# @param cache_ignore_headers
1313
# Specifies HTTP header(s) that should not be stored in the cache.
1414
#
15+
# @param default_cache_enable
16+
# Default value is true, which enables "CacheEnable disk /" in disk_cache.conf for the webserver. This would cache
17+
# every request to apache by default for every vhost. If set to false the default cache all behaviour is supressed.
18+
# You can then control this behaviour in individual vhosts by explicitly defining CacheEnable.
19+
#
1520
# @note
1621
# Apache 2.2, mod_disk_cache installed. On Apache 2.4, mod_cache_disk installed.
1722
#
@@ -20,6 +25,7 @@
2025
class apache::mod::disk_cache (
2126
$cache_root = undef,
2227
$cache_ignore_headers = undef,
28+
Boolean $default_cache_enable = true,
2329
) {
2430
include apache
2531
if $cache_root {

spec/classes/mod/disk_cache_spec.rb

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,59 @@
4747
.with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/apache2\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie})
4848
}
4949
end
50+
context 'with $default_cache_enable = false' do
51+
let :pre_condition do
52+
'class{ "apache":
53+
apache_version => "2.4",
54+
default_mods => ["cache"],
55+
mod_dir => "/tmp/junk",
56+
}'
57+
end
58+
59+
let(:params) { { 'default_cache_enable' => false } }
60+
61+
it { is_expected.to compile }
62+
it { is_expected.to contain_class('apache::mod::disk_cache') }
63+
it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') }
64+
it { is_expected.to contain_apache__mod('cache_disk') }
65+
it {
66+
is_expected.to contain_file('disk_cache.conf')
67+
.with(content: %r{CacheRoot \"\/var\/cache\/apache2\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\n})
68+
}
69+
end
70+
context 'with $default_cache_enable = true' do
71+
let :pre_condition do
72+
'class{ "apache":
73+
apache_version => "2.4",
74+
default_mods => ["cache"],
75+
mod_dir => "/tmp/junk",
76+
}'
77+
end
78+
79+
let(:params) { { 'default_cache_enable' => true } }
80+
81+
it { is_expected.to compile }
82+
it { is_expected.to contain_class('apache::mod::disk_cache') }
83+
it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') }
84+
it { is_expected.to contain_apache__mod('cache_disk') }
85+
it {
86+
is_expected.to contain_file('disk_cache.conf')
87+
.with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/apache2\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\n})
88+
}
89+
end
90+
context 'with $default_cache_enable = foo' do
91+
let :pre_condition do
92+
'class{ "apache":
93+
apache_version => "2.4",
94+
default_mods => ["cache"],
95+
mod_dir => "/tmp/junk",
96+
}'
97+
end
98+
99+
let(:params) { { 'default_cache_enable' => 'foo' } }
100+
101+
it { is_expected.not_to compile }
102+
end
50103
end
51104

52105
context 'on a RedHat 6-based OS' do
@@ -88,6 +141,59 @@
88141
.with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/httpd\/proxy\"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie})
89142
}
90143
end
144+
context 'with $default_cache_enable = false' do
145+
let :pre_condition do
146+
'class{ "apache":
147+
apache_version => "2.4",
148+
default_mods => ["cache"],
149+
mod_dir => "/tmp/junk",
150+
}'
151+
end
152+
153+
let(:params) { { 'default_cache_enable' => false } }
154+
155+
it { is_expected.to compile }
156+
it { is_expected.to contain_class('apache::mod::disk_cache') }
157+
it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') }
158+
it { is_expected.to contain_apache__mod('cache_disk') }
159+
it {
160+
is_expected.to contain_file('disk_cache.conf')
161+
.with(content: %r{CacheRoot \"\/var\/cache\/httpd\/proxy\"\nCacheDirLevels 2\nCacheDirLength 1\n})
162+
}
163+
end
164+
context 'with $default_cache_enable = true' do
165+
let :pre_condition do
166+
'class{ "apache":
167+
apache_version => "2.4",
168+
default_mods => ["cache"],
169+
mod_dir => "/tmp/junk",
170+
}'
171+
end
172+
173+
let(:params) { { 'default_cache_enable' => true } }
174+
175+
it { is_expected.to compile }
176+
it { is_expected.to contain_class('apache::mod::disk_cache') }
177+
it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') }
178+
it { is_expected.to contain_apache__mod('cache_disk') }
179+
it {
180+
is_expected.to contain_file('disk_cache.conf')
181+
.with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/httpd\/proxy\"\nCacheDirLevels 2\nCacheDirLength 1\n})
182+
}
183+
end
184+
context 'with $default_cache_enable = foo' do
185+
let :pre_condition do
186+
'class{ "apache":
187+
apache_version => "2.4",
188+
default_mods => ["cache"],
189+
mod_dir => "/tmp/junk",
190+
}'
191+
end
192+
193+
let(:params) { { 'default_cache_enable' => 'foo' } }
194+
195+
it { is_expected.not_to compile }
196+
end
91197
end
92198
context 'on a FreeBSD OS' do
93199
include_examples 'FreeBSD 10'
@@ -134,5 +240,58 @@
134240
.with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie})
135241
}
136242
end
243+
context 'with $default_cache_enable = false' do
244+
let :pre_condition do
245+
'class{ "apache":
246+
apache_version => "2.4",
247+
default_mods => ["cache"],
248+
mod_dir => "/tmp/junk",
249+
}'
250+
end
251+
252+
let(:params) { { 'default_cache_enable' => false } }
253+
254+
it { is_expected.to compile }
255+
it { is_expected.to contain_class('apache::mod::disk_cache') }
256+
it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') }
257+
it { is_expected.to contain_apache__mod('cache_disk') }
258+
it {
259+
is_expected.to contain_file('disk_cache.conf')
260+
.with(content: %r{CacheRoot \"\/var\/cache\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\n})
261+
}
262+
end
263+
context 'with $default_cache_enable = true' do
264+
let :pre_condition do
265+
'class{ "apache":
266+
apache_version => "2.4",
267+
default_mods => ["cache"],
268+
mod_dir => "/tmp/junk",
269+
}'
270+
end
271+
272+
let(:params) { { 'default_cache_enable' => true } }
273+
274+
it { is_expected.to compile }
275+
it { is_expected.to contain_class('apache::mod::disk_cache') }
276+
it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') }
277+
it { is_expected.to contain_apache__mod('cache_disk') }
278+
it {
279+
is_expected.to contain_file('disk_cache.conf')
280+
.with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\n})
281+
}
282+
end
283+
context 'with $default_cache_enable = foo' do
284+
let :pre_condition do
285+
'class{ "apache":
286+
apache_version => "2.4",
287+
default_mods => ["cache"],
288+
mod_dir => "/tmp/junk",
289+
}'
290+
end
291+
292+
let(:params) { { 'default_cache_enable' => 'foo' } }
293+
294+
it { is_expected.not_to compile }
295+
end
137296
end
138297
end

templates/mod/disk_cache.conf.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
<% if @default_cache_enable -%>
12
CacheEnable disk /
3+
<% end -%>
24
CacheRoot "<%= @_cache_root %>"
35
CacheDirLevels 2
46
CacheDirLength 1

0 commit comments

Comments
 (0)