Skip to content

Commit 79d3541

Browse files
authored
feat: improve cache policy in presets and config (#346)
- Add cache policy configuration to all framework presets with 7200s TTL for browser and edge - Update SPA and MPA rules to include set_cache_policy behavior - Add application parameter to createSPARules and createMPARules functions - Update rule names and descriptions to reflect cache policy setting - Simplify name field error message in schema validation - Update tests to reflect new cache policy behavior in
1 parent f4a1062 commit 79d3541

File tree

25 files changed

+371
-60
lines changed

25 files changed

+371
-60
lines changed

packages/config/src/configProcessor/helpers/schema.ts

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
import {
2-
ALL_REQUEST_VARIABLES,
3-
ALL_RESPONSE_VARIABLES,
4-
BUILD_BUNDLERS,
5-
COOKIE_BEHAVIORS,
6-
CUSTOM_PAGE_ERROR_CODES,
7-
CUSTOM_PAGE_TYPES,
8-
EDGE_CONNECTOR_DNS_RESOLUTION,
9-
EDGE_CONNECTOR_HMAC_TYPE,
10-
EDGE_CONNECTOR_HTTP_VERSION_POLICY,
11-
EDGE_CONNECTOR_LOAD_BALANCE_METHOD,
12-
EDGE_CONNECTOR_TRANSPORT_POLICY,
13-
EDGE_CONNECTOR_TYPES,
14-
FIREWALL_RATE_LIMIT_BY,
15-
FIREWALL_RATE_LIMIT_TYPES,
16-
FIREWALL_VARIABLES,
17-
FIREWALL_WAF_MODES,
18-
HEADER_BEHAVIORS,
19-
ID_BEHAVIORS,
20-
NETWORK_LIST_TYPES,
21-
NO_ARGS_BEHAVIORS,
22-
RULE_CONDITIONALS,
23-
RULE_OPERATORS_WITH_VALUE,
24-
RULE_OPERATORS_WITHOUT_VALUE,
25-
SPECIAL_VARIABLES,
26-
STRING_BEHAVIORS,
27-
WORKLOAD_HTTP_VERSIONS,
28-
WORKLOAD_MTLS_VERIFICATION,
29-
WORKLOAD_TLS_VERSIONS,
30-
WORKLOADS_ACCESS_TYPES,
2+
ALL_REQUEST_VARIABLES,
3+
ALL_RESPONSE_VARIABLES,
4+
BUILD_BUNDLERS,
5+
COOKIE_BEHAVIORS,
6+
CUSTOM_PAGE_ERROR_CODES,
7+
CUSTOM_PAGE_TYPES,
8+
EDGE_CONNECTOR_DNS_RESOLUTION,
9+
EDGE_CONNECTOR_HMAC_TYPE,
10+
EDGE_CONNECTOR_HTTP_VERSION_POLICY,
11+
EDGE_CONNECTOR_LOAD_BALANCE_METHOD,
12+
EDGE_CONNECTOR_TRANSPORT_POLICY,
13+
EDGE_CONNECTOR_TYPES,
14+
FIREWALL_RATE_LIMIT_BY,
15+
FIREWALL_RATE_LIMIT_TYPES,
16+
FIREWALL_VARIABLES,
17+
FIREWALL_WAF_MODES,
18+
HEADER_BEHAVIORS,
19+
ID_BEHAVIORS,
20+
NETWORK_LIST_TYPES,
21+
NO_ARGS_BEHAVIORS,
22+
RULE_CONDITIONALS,
23+
RULE_OPERATORS_WITH_VALUE,
24+
RULE_OPERATORS_WITHOUT_VALUE,
25+
SPECIAL_VARIABLES,
26+
STRING_BEHAVIORS,
27+
WORKLOAD_HTTP_VERSIONS,
28+
WORKLOAD_MTLS_VERIFICATION,
29+
WORKLOAD_TLS_VERSIONS,
30+
WORKLOADS_ACCESS_TYPES,
3131
} from '../../constants';
3232

3333
const createCriteriaBaseSchema = (isRequestPhase = false) => ({
@@ -609,8 +609,7 @@ const azionConfigSchema = {
609609
type: 'string',
610610
minLength: 1,
611611
maxLength: 250,
612-
pattern: "^[a-zA-Z0-9 \\-.',|]+$",
613-
errorMessage: "The 'name' field must be a string between 1-250 characters with valid pattern.",
612+
errorMessage: "The 'name' field must be a string with 1 to 250 characters",
614613
},
615614
stale: {
616615
type: 'boolean',
@@ -638,13 +637,13 @@ const azionConfigSchema = {
638637
},
639638
required: ['enabled'],
640639
if: {
641-
properties: { enabled: { const: true } }
640+
properties: { enabled: { const: true } },
642641
},
643642
then: {
644643
required: ['enabled', 'topology'],
645644
errorMessage: {
646-
required: "When 'enabled' is true, 'topology' is required in the 'tiered_cache' object."
647-
}
645+
required: "When 'enabled' is true, 'topology' is required in the 'tiered_cache' object.",
646+
},
648647
},
649648
additionalProperties: false,
650649
errorMessage: {

packages/config/src/rules/request/createMPA.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('createMPARules', () => {
1717
// Check static assets rule
1818
const staticAssetsRule = rules.request?.[0];
1919
expect(staticAssetsRule).toEqual({
20-
name: 'Deliver Static Assets',
21-
description: 'Deliver static assets directly from storage',
20+
name: 'Deliver Static Assets and Set Cache Policy',
21+
description: 'Deliver static assets directly from storage and set cache policy',
2222
active: true,
2323
criteria: [
2424
[
@@ -37,6 +37,12 @@ describe('createMPARules', () => {
3737
value: 'name-connector',
3838
},
3939
},
40+
{
41+
type: 'set_cache_policy',
42+
attributes: {
43+
value: 'name-application',
44+
},
45+
},
4046
{
4147
type: 'deliver',
4248
},

packages/config/src/rules/request/createMPA.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ import { ALL_EXTENSIONS } from '../constants';
1212
*
1313
* @param options Configuration options for the MPA rules
1414
* @param options.connector The name of the edge connector to use
15+
* @param options.application The name of the application to use
1516
* @param options.staticExtensions List of file extensions to be treated as static assets
1617
* @returns Array of rules configured for MPA hosting on Azion Edge
1718
*/
1819
export function createMPARules(
1920
options: {
2021
connector?: string;
22+
application?: string;
2123
staticExtensions?: string[];
2224
} = {},
2325
): AzionRules {
24-
const { connector = 'name-connector', staticExtensions = ALL_EXTENSIONS } = options;
26+
const { connector = 'name-connector', application = 'name-application', staticExtensions = ALL_EXTENSIONS } = options;
2527

2628
return {
2729
request: [
2830
{
29-
name: 'Deliver Static Assets',
30-
description: 'Deliver static assets directly from storage',
31+
name: 'Deliver Static Assets and Set Cache Policy',
32+
description: 'Deliver static assets directly from storage and set cache policy',
3133
active: true,
3234
criteria: [
3335
[
@@ -46,6 +48,12 @@ export function createMPARules(
4648
value: connector,
4749
},
4850
},
51+
{
52+
type: 'set_cache_policy',
53+
attributes: {
54+
value: application,
55+
},
56+
},
4957
{
5058
type: 'deliver',
5159
},

packages/config/src/rules/request/createSPA.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('createSPARules', () => {
1717
// Check static assets rule
1818
const staticAssetsRule = rules.request?.[0];
1919
expect(staticAssetsRule).toEqual({
20-
name: 'Deliver Static Assets',
21-
description: 'Deliver static assets directly from storage',
20+
name: 'Deliver Static Assets and Set Cache Policy',
21+
description: 'Deliver static assets directly from storage and set cache policy',
2222
active: true,
2323
criteria: [
2424
[
@@ -37,6 +37,12 @@ describe('createSPARules', () => {
3737
value: 'name-connector',
3838
},
3939
},
40+
{
41+
type: 'set_cache_policy',
42+
attributes: {
43+
value: 'name-application',
44+
},
45+
},
4046
{
4147
type: 'deliver',
4248
},

packages/config/src/rules/request/createSPA.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ import { ALL_EXTENSIONS } from '../constants';
1212
*
1313
* @param options Configuration options for the SPA rules
1414
* @param options.connector The name of the edge connector to use
15+
* @param options.application The name of the application to use
1516
* @param options.staticExtensions List of file extensions to be treated as static assets
1617
* @returns Array of rules configured for SPA hosting on Azion Edge
1718
*/
1819
export function createSPARules(
1920
options: {
2021
connector?: string;
22+
application?: string;
2123
staticExtensions?: string[];
2224
} = {},
2325
): AzionRules {
24-
const { connector = 'name-connector', staticExtensions = ALL_EXTENSIONS } = options;
26+
const { connector = 'name-connector', application = 'name-application', staticExtensions = ALL_EXTENSIONS } = options;
2527

2628
return {
2729
request: [
2830
{
29-
name: 'Deliver Static Assets',
30-
description: 'Deliver static assets directly from storage',
31+
name: 'Deliver Static Assets and Set Cache Policy',
32+
description: 'Deliver static assets directly from storage and set cache policy',
3133
active: true,
3234
criteria: [
3335
[
@@ -46,6 +48,12 @@ export function createSPARules(
4648
value: connector,
4749
},
4850
},
51+
{
52+
type: 'set_cache_policy',
53+
attributes: {
54+
value: application,
55+
},
56+
},
4957
{
5058
type: 'deliver',
5159
},

packages/presets/src/presets/angular/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,20 @@ const config: AzionConfig = {
2727
applications: [
2828
{
2929
name: '$APPLICATION_NAME',
30+
cache: [
31+
{
32+
name: '$APPLICATION_NAME',
33+
browser: {
34+
maxAgeSeconds: 7200,
35+
},
36+
edge: {
37+
maxAgeSeconds: 7200,
38+
},
39+
},
40+
],
3041
rules: createSPARules({
3142
connector: '$CONNECTOR_NAME',
43+
application: '$APPLICATION_NAME',
3244
}),
3345
},
3446
],

packages/presets/src/presets/astro/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,20 @@ const config: AzionConfig = {
2727
applications: [
2828
{
2929
name: '$APPLICATION_NAME',
30+
cache: [
31+
{
32+
name: '$APPLICATION_NAME',
33+
browser: {
34+
maxAgeSeconds: 7200,
35+
},
36+
edge: {
37+
maxAgeSeconds: 7200,
38+
},
39+
},
40+
],
3041
rules: createMPARules({
3142
connector: '$CONNECTOR_NAME',
43+
application: '$APPLICATION_NAME',
3244
}),
3345
},
3446
],

packages/presets/src/presets/docusaurus/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,20 @@ const config: AzionConfig = {
2727
applications: [
2828
{
2929
name: '$APPLICATION_NAME',
30+
cache: [
31+
{
32+
name: '$APPLICATION_NAME',
33+
browser: {
34+
maxAgeSeconds: 7200,
35+
},
36+
edge: {
37+
maxAgeSeconds: 7200,
38+
},
39+
},
40+
],
3041
rules: createMPARules({
3142
connector: '$CONNECTOR_NAME',
43+
application: '$APPLICATION_NAME',
3244
}),
3345
},
3446
],

packages/presets/src/presets/eleventy/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,20 @@ const config: AzionConfig = {
2727
applications: [
2828
{
2929
name: '$APPLICATION_NAME',
30+
cache: [
31+
{
32+
name: '$APPLICATION_NAME',
33+
browser: {
34+
maxAgeSeconds: 7200,
35+
},
36+
edge: {
37+
maxAgeSeconds: 7200,
38+
},
39+
},
40+
],
3041
rules: createMPARules({
3142
connector: '$CONNECTOR_NAME',
43+
application: '$APPLICATION_NAME',
3244
}),
3345
},
3446
],

packages/presets/src/presets/gatsby/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,20 @@ const config: AzionConfig = {
2727
applications: [
2828
{
2929
name: '$APPLICATION_NAME',
30+
cache: [
31+
{
32+
name: '$APPLICATION_NAME',
33+
browser: {
34+
maxAgeSeconds: 7200,
35+
},
36+
edge: {
37+
maxAgeSeconds: 7200,
38+
},
39+
},
40+
],
3041
rules: createMPARules({
3142
connector: '$CONNECTOR_NAME',
43+
application: '$APPLICATION_NAME',
3244
}),
3345
},
3446
],

0 commit comments

Comments
 (0)