Initial support for HAproxy cache

This commit is contained in:
Andrew Heberle
2019-08-09 09:10:18 +08:00
parent 1cdee5fba6
commit 44425f8678
5 changed files with 70 additions and 0 deletions
@@ -307,6 +307,13 @@
<help><![CDATA[Declare how idle HTTP connections may be shared between requests.]]></help>
<advanced>true</advanced>
</field>
<field>
<id>backend.tuning_caching</id>
<label>Enable Caching</label>
<type>checkbox</type>
<help><![CDATA[Enable caching of responses from this backend. The HAProxy cache must be enabled under Settings before this will have any effect.]]></help>
<advanced>true</advanced>
</field>
<field>
<label>Rules</label>
<type>header</type>
@@ -318,5 +318,25 @@
<advanced>true</advanced>
</field>
</subtab>
<subtab id="haproxy-general-cache" description="Cache">
<field>
<id>haproxy.general.cache.enabled</id>
<label>Cache enabled</label>
<type>checkbox</type>
<help><![CDATA[Enable HAProxy's cache which was designed to perform cache on small objects (favicon, css...). This is a minimalist low-maintenance cache which runs in RAM.]]></help>
</field>
<field>
<id>haproxy.general.cache.totalMaxSize</id>
<label>Maximum Size of Cache (MB)</label>
<type>text</type>
<help><![CDATA[Define the size in RAM of the cache in megabytes. This size is split in blocks of 1kB which are used by the cache entries. Its maximum value is 4095.]]></help>
</field>
<field>
<id>haproxy.general.cache.maxAge</id>
<label>Maximum Object Age (sec)</label>
<type>text</type>
<help><![CDATA[Define the maximum expiration duration. Cache-Control response headers will be respected if they are less than this value. The default value is 60 seconds.]]></help>
</field>
</subtab>
</tab>
</form>
@@ -324,6 +324,26 @@
<Required>N</Required>
</customOptions>
</stats>
<cache>
<enabled type="BooleanField">
<default>0</default>
<Required>N</Required>
</enabled>
<totalMaxSize type="IntegerField">
<MinimumValue>1</MinimumValue>
<MaximumValue>4095</MaximumValue>
<default>4</default>
<Required>Y</Required>
<ValidationMessage>Please specify a value between 1 and 4095.</ValidationMessage>
</totalMaxSize>
<maxAge type="IntegerField">
<MinimumValue>1</MinimumValue>
<MaximumValue>3600</MaximumValue>
<default>60</default>
<Required>N</Required>
<ValidationMessage>Please specify a value between 1 and 3600.</ValidationMessage>
</maxAge>
</cache>
</general>
<frontends>
<frontend type="ArrayField">
@@ -976,6 +996,10 @@
<always>Always</always>
</OptionValues>
</tuning_httpreuse>
<tuning_caching type="BooleanField">
<default>0</default>
<Required>N</Required>
</tuning_caching>
<linkedActions type="ModelRelationField">
<Model>
<template>
@@ -8,6 +8,7 @@
<DefaultParameters VisibleName="Default Parameters" url="/ui/haproxy#subtab_haproxy-general-defaults"/>
<LoggingConfiguration VisibleName="Logging Configuration" url="/ui/haproxy#subtab_haproxy-general-logging"/>
<StatisticsConfiguration VisibleName="Statistics Configuration" url="/ui/haproxy#subtab_haproxy-general-statistics"/>
<CacheConfiguration VisibleName="Cache Configuration" url="/ui/haproxy#subtab_haproxy-general-cache"/>
<Frontends VisibleName="Frontends" url="/ui/haproxy#frontends"/>
<Backends VisibleName="Backends" url="/ui/haproxy#backends"/>
<Servers VisibleName="Servers" url="/ui/haproxy#servers"/>
@@ -872,6 +872,20 @@ global
{% endfor %}
{%- endif -%}
{# ############################### #}
{# CACHE #}
{# ############################### #}
{%- if helpers.exists('OPNsense.HAProxy.general.cache') and OPNsense.HAProxy.general.cache.enabled|default("") == "1" %}
cache opnsense-haproxy-cache
{% if OPNsense.HAProxy.general.cache.totalMaxSize|default("") != "" %}
total-max-size {{OPNsense.HAProxy.general.cache.totalMaxSize}}
{% endif %}
{% if OPNsense.HAProxy.general.cache.maxAge|default("") != "" %}
max-age {{OPNsense.HAProxy.general.cache.maxAge}}
{% endif %}
{%- endif -%}
{# ############################### #}
{# DEFAULTS #}
{# ############################### #}
@@ -1290,6 +1304,10 @@ backend {{backend.name}}
{% if backend.tuning_httpreuse|default("") != "" and backend.mode == "http" %}
http-reuse {{backend.tuning_httpreuse}}
{% endif %}
{% if helpers.exists('OPNsense.HAProxy.general.cache') and OPNsense.HAProxy.general.cache.enabled|default("") == "1" and if backend.tuning_caching|default("") == "1" and backend.mode == "http" %}
http-request cache-use opnsense-haproxy-cache
http-response cache-store opnsense-haproxy-cache
{% endif %}
{% if backend.tuning_defaultserver|default("") != "" %}
default-server {{backend.tuning_defaultserver}}
{% endif %}