diff --git a/REFERENCE.md b/REFERENCE.md
index 2c70b2d6..9c481ab2 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -275,11 +275,11 @@ Default value: `false`
##### `cache`
-Data type: `Variant[Boolean,Enum['no-negative']]`
+Data type: `Optional[Variant[Boolean,Enum['no-negative']]]`
-Takes a boolean argument or "no-negative".
+Takes a boolean argument or "no-negative". If left `undef` the cache setting will not be modified.
-Default value: `false`
+Default value: `undef`
##### `dns_stub_listener`
diff --git a/manifests/init.pp b/manifests/init.pp
index 5c77850a..527da5bc 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -61,7 +61,7 @@
# "opportunistic" and "false" (default) to "no".
#
# @param cache
-# Takes a boolean argument or "no-negative".
+# Takes a boolean argument or "no-negative". If left `undef` the cache setting will not be modified.
#
# @param dns_stub_listener
# Takes a boolean argument or one of "udp" and "tcp".
@@ -201,7 +201,7 @@
Optional[Variant[Boolean,Enum['resolve']]] $multicast_dns = undef,
Optional[Variant[Boolean,Enum['allow-downgrade']]] $dnssec = undef,
Variant[Boolean,Enum['yes', 'opportunistic', 'no']] $dnsovertls = false,
- Variant[Boolean,Enum['no-negative']] $cache = false,
+ Optional[Variant[Boolean,Enum['no-negative']]] $cache = undef,
Optional[Variant[Boolean,Enum['udp','tcp']]] $dns_stub_listener = undef,
Optional[Array[String[1]]] $dns_stub_listener_extra = undef,
Boolean $manage_resolv_conf = true,
diff --git a/manifests/resolved.pp b/manifests/resolved.pp
index dacee3c0..e4b924b6 100644
--- a/manifests/resolved.pp
+++ b/manifests/resolved.pp
@@ -222,7 +222,7 @@
default => $cache,
}
- if $cache {
+ if $_cache {
ini_setting { 'cache':
ensure => 'present',
value => $_cache,
diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb
index fcc09152..af5597c4 100644
--- a/spec/classes/init_spec.rb
+++ b/spec/classes/init_spec.rb
@@ -194,6 +194,25 @@
}
end
+ context 'when enabling resolved with false cache variant' do
+ let(:params) do
+ {
+ manage_resolved: true,
+ cache: false,
+ }
+ end
+
+ it { is_expected.to create_service('systemd-resolved').with_ensure('running') }
+ it { is_expected.to create_service('systemd-resolved').with_enable(true) }
+
+ it {
+ expect(subject).to contain_ini_setting('cache').with(
+ path: '/etc/systemd/resolved.conf',
+ value: 'no'
+ )
+ }
+ end
+
context 'with alternate target' do
let(:params) do
{