-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added cache_disk #2521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Added cache_disk #2521
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b57883e
Added cache_disk
ThomasMinor 60c3d46
Fixing parameters in deprecated module to keep
dploeger ec10dff
Optimization
dploeger c39316f
Suggestions from Code Review
f86abf2
Update manifests/mod/disk_cache.pp
aeef7fb
Update spec/classes/mod/cache_disk_spec.rb
9fdf754
Rubocop fixes
dploeger a7e55d3
Update manifests/mod/cache_disk.pp
9e6e34e
Removed references to Apache 2.2
dploeger ce2a3a9
Update manifests/mod/cache_disk.pp
a84601c
fix: fix apache cache_ignore_header regression
ThomasMinor 6c29fbf
refactor: change config line generation to simpler and more readable …
ThomasMinor 873dc6b
fix: handle undefined value of $cache_ignore_headers in deprecated mo…
ThomasMinor 8b998bb
fix: fix problems with deprecated modules and add additional test for…
ThomasMinor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,58 @@ | ||
# @summary | ||
# Installs `mod_cache` | ||
# | ||
# | ||
# @param cache_ignore_headers | ||
# Specifies HTTP header(s) that should not be stored in the cache. | ||
# | ||
# @param cache_default_expire | ||
# The default duration to cache a document when no expiry date is specified. | ||
# | ||
# @param cache_max_expire | ||
# The maximum time in seconds to cache a document | ||
# | ||
# @param cache_ignore_no_lastmod | ||
# Ignore the fact that a response has no Last Modified header. | ||
# | ||
# @param cache_header | ||
# Add an X-Cache header to the response. | ||
# | ||
# @param cache_lock | ||
# Enable the thundering herd lock. | ||
# | ||
# @param cache_ignore_cache_control | ||
# Ignore request to not serve cached content to client | ||
# | ||
# @see https://httpd.apache.org/docs/current/mod/mod_cache.html for additional documentation. | ||
# | ||
class apache::mod::cache { | ||
::apache::mod { 'cache': } | ||
class apache::mod::cache ( | ||
Array[String[1]] $cache_ignore_headers = [], | ||
Optional[Integer] $cache_default_expire = undef, | ||
Optional[Integer] $cache_max_expire = undef, | ||
Optional[Apache::OnOff] $cache_ignore_no_lastmod = undef, | ||
Optional[Apache::OnOff] $cache_header = undef, | ||
Optional[Apache::OnOff] $cache_lock = undef, | ||
Optional[Apache::OnOff] $cache_ignore_cache_control = undef, | ||
) { | ||
include apache | ||
apache::mod { 'cache': } | ||
|
||
$_configuration_file_name = 'cache.conf' | ||
|
||
file { $_configuration_file_name: | ||
ensure => file, | ||
path => "${apache::mod_dir}/${_configuration_file_name}", | ||
mode => $apache::file_mode, | ||
content => epp('apache/mod/cache.conf.epp', { | ||
cache_ignore_headers => $cache_ignore_headers, | ||
cache_default_expire => $cache_default_expire, | ||
cache_max_expire => $cache_max_expire, | ||
cache_ignore_no_lastmod => $cache_ignore_no_lastmod, | ||
cache_header => $cache_header, | ||
cache_lock => $cache_lock, | ||
cache_ignore_cache_control => $cache_ignore_cache_control, | ||
}), | ||
require => Exec["mkdir ${apache::mod_dir}"], | ||
before => File[$apache::mod_dir], | ||
notify => Class['apache::service'], | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# @summary | ||
# Installs and configures `mod_cache_disk`. | ||
# | ||
# @description | ||
# This will install an configure the proper module depending on the used apache version, so | ||
# - mod_cache_disk for apache version >= 2.4 | ||
# - mod_disk_cache for older apache versions | ||
# | ||
# @param cache_root | ||
# Defines the name of the directory on the disk to contain cache files. | ||
# Default depends on the Apache version and operating system: | ||
# - Debian: /var/cache/apache2/mod_cache_disk | ||
# - FreeBSD: /var/cache/mod_cache_disk | ||
# - Red Hat: /var/cache/httpd/proxy | ||
# | ||
# @param cache_enable | ||
# Defines an array of directories to cache, the default is none | ||
# | ||
# @param cache_dir_length | ||
# The number of characters in subdirectory names | ||
# | ||
# @param cache_dir_levels | ||
# The number of levels of subdirectories in the cache. | ||
# | ||
# @param cache_max_filesize | ||
# The maximum size (in bytes) of a document to be placed in the cache | ||
# | ||
# @param cache_ignore_headers | ||
# DEPRECATED Ignore request to not serve cached content to client (included for compatibility reasons to support disk_cache) | ||
# | ||
# @param configuration_file_name | ||
# DEPRECATED Name of module configuration file (used for the compatibility layer for disk_cache) | ||
# | ||
# @see https://httpd.apache.org/docs/2.4/mod/mod_cache_disk.html | ||
# | ||
class apache::mod::cache_disk ( | ||
Optional[Stdlib::Absolutepath] $cache_root = undef, | ||
Array[String] $cache_enable = [], | ||
Optional[Integer] $cache_dir_length = undef, | ||
Optional[Integer] $cache_dir_levels = undef, | ||
Optional[Integer] $cache_max_filesize = undef, | ||
Optional[String] $cache_ignore_headers = undef, | ||
Optional[String] $configuration_file_name = undef, | ||
) { | ||
include apache | ||
|
||
if $cache_ignore_headers { | ||
deprecation( | ||
'apache::mod::cache_disk', | ||
'The parameter cache_ignore_headers is deprecated. Please use apache::mod::cache::cache_ignore_headers instead.' | ||
) | ||
} | ||
|
||
$_cache_root = $cache_root ? { | ||
undef => $facts['os']['family'] ? { | ||
'debian' => '/var/cache/apache2/mod_cache_disk', | ||
'redhat' => '/var/cache/httpd/proxy', | ||
'freebsd' => '/var/cache/mod_cache_disk', | ||
}, | ||
default => $cache_root, | ||
} | ||
$_configuration_file_name = pick($configuration_file_name, 'cache_disk.conf') | ||
$_class_name = 'apache::mod::cache_disk' | ||
|
||
apache::mod { 'cache_disk': } | ||
|
||
Class['apache::mod::cache'] -> Class[$_class_name] | ||
|
||
file { $_configuration_file_name: | ||
ensure => file, | ||
path => "${apache::mod_dir}/${_configuration_file_name}", | ||
mode => $apache::file_mode, | ||
content => epp('apache/mod/cache_disk.conf.epp', { | ||
cache_root => $_cache_root, | ||
cache_enable => $cache_enable, | ||
cache_dir_length => $cache_dir_length, | ||
cache_dir_levels => $cache_dir_levels, | ||
cache_max_filesize => $cache_max_filesize, | ||
cache_ignore_headers => $cache_ignore_headers, | ||
}), | ||
require => Exec["mkdir ${apache::mod_dir}"], | ||
before => File[$apache::mod_dir], | ||
notify => Class['apache::service'], | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'apache::mod::cache_disk', type: :class do | ||
context 'on a Debian OS' do | ||
include_examples 'Debian 11' | ||
|
||
let(:params) do | ||
{ | ||
cache_enable: ['/'], | ||
} | ||
end | ||
|
||
let :pre_condition do | ||
'class{ "apache": | ||
default_mods => ["cache"], | ||
mod_dir => "/tmp/junk", | ||
}' | ||
end | ||
|
||
it { is_expected.to compile } | ||
it { is_expected.to contain_class('apache::mod::cache_disk') } | ||
it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Cache_disk]') } | ||
it { is_expected.to contain_apache__mod('cache_disk') } | ||
|
||
default_config = %r{CacheEnable disk /\nCacheRoot "/var/cache/apache2/mod_cache_disk"} | ||
|
||
it { is_expected.to contain_file('cache_disk.conf').with(content: default_config) } | ||
|
||
describe 'with multiple cache_enable parameters' do | ||
let(:params) do | ||
{ | ||
cache_enable: ['/', '/something'], | ||
} | ||
end | ||
|
||
it { | ||
expect(subject).to contain_file('cache_disk.conf') | ||
.with(content: %r{CacheEnable disk /\nCacheEnable disk /something\nCacheRoot "/var/cache/apache2/mod_cache_disk"}) | ||
} | ||
end | ||
|
||
describe 'with cache_dir_length' do | ||
let(:params) do | ||
{ | ||
cache_dir_length: 2, | ||
cache_enable: ['/'], | ||
} | ||
end | ||
|
||
it { | ||
expect(subject).to contain_file('cache_disk.conf') | ||
.with(content: %r{#{default_config}\nCacheDirLength 2}) | ||
} | ||
end | ||
|
||
describe 'with cache_dir_levels' do | ||
let(:params) do | ||
{ | ||
cache_dir_levels: 2, | ||
cache_enable: ['/'], | ||
} | ||
end | ||
|
||
it { | ||
expect(subject).to contain_file('cache_disk.conf') | ||
.with(content: %r{#{default_config}\nCacheDirLevels 2}) | ||
} | ||
end | ||
end | ||
|
||
context 'on a RedHat 8-based OS' do | ||
include_examples 'RedHat 8' | ||
|
||
let(:params) do | ||
{ | ||
cache_enable: ['/'], | ||
} | ||
end | ||
|
||
let :pre_condition do | ||
'class{ "apache": | ||
default_mods => ["cache"], | ||
mod_dir => "/tmp/junk", | ||
}' | ||
end | ||
|
||
it { is_expected.to compile } | ||
|
||
it { | ||
expect(subject).to contain_file('cache_disk.conf') | ||
.with(content: %r{CacheEnable disk /\nCacheRoot "/var/cache/httpd/proxy"}) | ||
} | ||
end | ||
|
||
context 'on a FreeBSD OS' do | ||
include_examples 'FreeBSD 10' | ||
|
||
let(:params) do | ||
{ | ||
cache_enable: ['/'], | ||
} | ||
end | ||
|
||
let :pre_condition do | ||
'class{ "apache": | ||
default_mods => ["cache"], | ||
mod_dir => "/tmp/junk", | ||
}' | ||
end | ||
|
||
it { is_expected.to compile } | ||
|
||
it { | ||
expect(subject).to contain_file('cache_disk.conf') | ||
.with(content: %r{CacheEnable disk /\nCacheRoot "/var/cache/mod_cache_disk"}) | ||
} | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.