-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.ts
More file actions
102 lines (100 loc) · 5.63 KB
/
Copy pathconstants.ts
File metadata and controls
102 lines (100 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { CacheLayer } from './types';
export const CACHE_LAYERS: CacheLayer[] = [
{
id: 'browser',
title: 'Browser & Client Cache',
subtitle: 'First line of defense',
description: 'When a student clicks "View Course Participants", the browser checks its local stores before even touching the network.',
moodleContext: 'Static assets like course icons (Moodle pix), user profile pics, and previously fetched JSON payloads might reside here.',
techStack: ['HTTP Headers (Cache-Control)', 'Local Storage', 'Service Workers'],
latencyReduction: '1ms - 10ms',
type: 'client',
details: [
'Cached Files: .js, .css, .png, .jpg, .svg, .woff2, .json',
'ETag validation: Checking if course icons or scripts have updated.',
'Service Workers: Intercepting API calls for Moodle Mobile offline support.',
'Memory Cache: Storing frequently used UI components like the navigation drawer.'
],
expirationLogic: {
mechanism: 'Cache-Control & Versioning',
description: 'Moodle uses "Cache Busting" by appending a version number (rev=123) to URLs. When the site updates, the URL changes, forcing the browser to fetch the new file. Otherwise, files expire after the Max-Age (often 1 year) is reached.'
}
},
{
id: 'cdn',
title: 'Cloudflare / AWS CloudFront CDN',
subtitle: 'The Edge Network',
description: 'A global network of servers that caches content physically closer to the student to reduce speed-of-light delays.',
moodleContext: 'Moodle core JS, CSS, and media files are served from the nearest Cloudflare or CloudFront POP (Point of Presence).',
techStack: ['Cloudflare', 'AWS CloudFront'],
latencyReduction: '10ms - 50ms',
type: 'network',
details: [
'Media Assets: .mp4, .mp3, .pdf, .zip (Course materials)',
'Static Web Assets: .js, .css, .scss, .ico, .svg, .webmanifest',
'Web Fonts: .woff, .woff2, .ttf, .otf (Moodle theme fonts)',
'Edge Caching: Serving theme images and core scripts from local edge nodes.'
],
expirationLogic: {
mechanism: 'TTL & Edge Invalidation',
description: 'Cloudflare respects origin headers but can be manually purged. When a teacher replaces a PDF, the old version stays at the edge until the TTL (Time-To-Live) expires or a "Purge Everything" command is sent via the AWS/Cloudflare console.'
}
},
{
id: 'opcache',
title: 'PHP OPcache',
subtitle: 'The Script Engine Speed-up',
description: 'PHP is an interpreted language. OPcache stores the compiled bytecode in shared memory, eliminating the need for re-parsing on every request.',
moodleContext: 'Moodle has thousands of PHP files. Without OPcache, every student request would require parsing the entire codebase.',
techStack: ['PHP Zend OPcache'],
latencyReduction: 'Significant CPU saving (2x-3x throughput)',
type: 'app',
details: [
'Eliminates the overhead of reading and parsing PHP files from disk.',
'Shared memory allows all worker processes to access pre-compiled code instantly.',
'Essential for scaling Moodle on high-concurrency AWS instances.'
],
expirationLogic: {
mechanism: 'Timestamp Validation',
description: 'By default, PHP checks if the .php file has a newer timestamp than the cached bytecode. In high-performance Moodle production environments, this check is often disabled (validate_timestamps=0), requiring a manual restart of the PHP-FPM service to clear the cache after code changes.'
}
},
{
id: 'muc',
title: 'Moodle Universal Cache (MUC) via AWS Redis',
subtitle: 'Distributed Application Brain',
description: "Moodle's internal caching framework utilizing AWS ElastiCache for Redis to provide a high-speed, shared state across the web cluster.",
moodleContext: 'Stores the specific student list for Course ID: 101 in Redis after it is retrieved from RDS the first time.',
techStack: ['AWS Redis (ElastiCache)', 'Redis MUC Plugin'],
latencyReduction: '1ms - 5ms (Redis Access)',
type: 'app',
details: [
'Application Cache: Shared course data across all EC2 web nodes.',
'Session Cache: Ensuring session persistence in a multi-server environment.',
'Distributed Locking: Prevents multiple nodes from running the same expensive calculation.'
],
expirationLogic: {
mechanism: 'Programmatic Invalidation',
description: 'Moodle manually triggers a Redis "Delete" key command whenever a student is added to or removed from a course. This ensures the "Student List" cache is purged immediately so the next request gets fresh data from RDS.'
}
},
{
id: 'db-cache',
title: 'Database Engine Caching (RDS)',
subtitle: 'The Storage Guard',
description: 'The database engine (Amazon RDS) maintains internal buffers to avoid hitting the physical EBS volumes for every query.',
moodleContext: 'The query `SELECT * FROM mdl_user` might be answered entirely from the Aurora/MySQL Buffer Pool in RAM.',
techStack: ['AWS RDS (Aurora/MySQL)', 'InnoDB Buffer Pool'],
latencyReduction: '5ms - 50ms',
type: 'data',
details: [
'LRU (Least Recently Used) data pages kept in high-speed RAM buffers.',
'Index structures cached for near-instant primary key lookups.',
'Reduced IOPS costs by minimizing physical disk reads.'
],
expirationLogic: {
mechanism: 'LRU Eviction & Dirty Page Flushes',
description: 'This cache is "Least Recently Used." If the RAM (Buffer Pool) gets full, the database evicts the oldest data to make room for new student queries. When data is written to RDS, the cached version is marked "dirty" and eventually synced to physical disk.'
}
}
];