SlideShare a Scribd company logo
MUC
Moodle Universal Cache
Tim Hunt
Introduction
What is a cache
A place to keep data that would take time to re-compute
A cache stores values identified by a key
E.g. list of activities in a course, stored by course id
Caches may get purged at any time
Cannot store real data there, just derived values for
performance
Why have a cache system?
Developers want to do stuff with data, not re-implement
caching
Want to be able to use different back-end stores
Disc, Memcache, REDIS, …
cachestore_ is a plugin type
Admins should control which data goes in which store
Cache performance
Typical call to cache::get For a typical page
• 0.5 ms data fetched from Memcache 150
• 0.05 ms data in static acceleration 700
For comparison: typical DB query
• 3 ms 40
Using caches
Typical use
$cache = cache::make('core', 'string');
$strings = $cache->get($component);
if ($strings === false) {
$strings = load_strings($component);
$cache->set($component, $strings);
}
Defining your cache
In db/caches.php in your plugin. E.g. from lib/db/caches.php
$definitions = array(
// Used to store processed lang files.
// Keys used are revision, lang and component of the string file.
// Static acceleration size is based on student access of the site.
'string' => array(
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'simpledata' => true,
'staticacceleration' => true, // Metadata helps cache
'staticaccelerationsize' => 30, // system handle the data
'canuselocalstore' => true, // efficiently.
),
);
$string['cachedef_string'] = 'Language string cache';
Types of cache
Application – Data that applies throughout Moodle
E.g. list of activities in each course / language strings
Session – Data that is relevant while a user is logged in
E.g. list of all course categories this user can access
Request – Data within the handling of one request
E.g. list of temporary tables
Clearing the cache
$cache = cache::make('core', 'questiondata');
$cache->delete($questionid);
cache::make('core', 'questiondata')->purge();
Recommended: just clear out what has changed
Dangerous
Also not recommended: time-to-live in cache definition
Bulk actions
$cache->get_many(['key1', 'key2']);
// ['key1' => 'value1', 'key2' => 'value2']
$cache->set_many(
['key1' => 'value1', 'key2' => 'value2']);
$cache->delete_many(['key1', 'key2']);
Advanced use: data source
Data source: why?
Avoids the normal
“is this in the cache? Yes: good; No, re-compute”
Tell the cache where to get the data if it is not yet stored
Data source: definition
$definitions = array(
// Cache for question definitions. This is used by the question
// bank class. Users probably do not need to know about this cache.
// They will just call question_bank::load_question.
'questiondata' => array(
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true, // The id of the question is used.
'requiredataguarantee' => false,
'datasource' => 'question_finder',
'datasourcefile' => 'question/engine/bank.php',
),
)
class question_finder implements cache_data_source {
public static function get_instance_for_cache(cache_definition $definition) {
return self::get_instance(); // Singleton pattern.
}
public function load_for_cache($questionid) {
global $DB;
$questiondata = $DB->get_record_sql('SELECT q.*, qc.contextid
FROM {question} q
JOIN {question_categories} qc ON q.category = qc.id
WHERE q.id = :id', array('id' => $questionid), MUST_EXIST);
get_question_options($questiondata);
return $questiondata;
}
}
Data source: use
$cache = cache::make('core', 'questiondata');
$cache->get($questionid);
Data source: implementation
public function get($key, $strictness = IGNORE_MISSING) {
// ...
$result = $this->store->get($key);
// ...
if ($result === false) {
if ($this->loader !== false) {
$result = $this->loader->get($key);
} else {
if ($this->datasource !== false) {
$result = $this->datasource->load_for_cache($key);
}
}
}
// ...
}
Cache administration
Cache administration
E.g. https://learn2acct.open.ac.uk/cache/admin.php
Cache administration: continued
Cache administration:
continued
Cache administration: continued
Issues
Memcache purging
MUC lets you store many different caches in one backend
cache::purge(); should just clear one of those caches
With Memcache, cache::purge() wipes all caches
This is one of the reasons the VLE crashed in October
Moodle 3.2 now has REDIS cache store in core
We should consider switching
Complex keys
MUC tries to support keys that are not just ints or strings
However this hurts performance – best not to use it
This probably applies to other advanced MUC features
Caching is about performance
Simple is good
Automated tests
MUC caches are automatically cleared between each unit
test or Behat test
Useful links
https://docs.moodle.org/dev/Cache_API
https://docs.moodle.org/dev/Cache_API_-_Quick_reference
cache/README.md in the code
https://docs.moodle.org/dev/The_Moodle_Universal_Cache_(MUC)

More Related Content

What's hot

Backup and Restore with pfSense 2.4 - pfSense Hangout August 2017
Backup and Restore with pfSense 2.4 - pfSense Hangout August 2017Backup and Restore with pfSense 2.4 - pfSense Hangout August 2017
Backup and Restore with pfSense 2.4 - pfSense Hangout August 2017
Netgate
 
pfSense firewall workshop guide
pfSense firewall workshop guidepfSense firewall workshop guide
pfSense firewall workshop guide
Sopon Tumchota
 
Cuaderno de ingenieria psp1p
Cuaderno de ingenieria psp1pCuaderno de ingenieria psp1p
Cuaderno de ingenieria psp1p
aguilarlupitas
 
Sonar qube
Sonar qubeSonar qube
Sonar qube
penetration Tester
 
Microservices Architecture for Web Applications using Amazon AWS Cloud
Microservices Architecture for Web Applications using Amazon AWS CloudMicroservices Architecture for Web Applications using Amazon AWS Cloud
Microservices Architecture for Web Applications using Amazon AWS Cloud
Mitoc Group
 

What's hot (6)

Backup and Restore with pfSense 2.4 - pfSense Hangout August 2017
Backup and Restore with pfSense 2.4 - pfSense Hangout August 2017Backup and Restore with pfSense 2.4 - pfSense Hangout August 2017
Backup and Restore with pfSense 2.4 - pfSense Hangout August 2017
 
pfSense firewall workshop guide
pfSense firewall workshop guidepfSense firewall workshop guide
pfSense firewall workshop guide
 
Netflow slides
Netflow slidesNetflow slides
Netflow slides
 
Cuaderno de ingenieria psp1p
Cuaderno de ingenieria psp1pCuaderno de ingenieria psp1p
Cuaderno de ingenieria psp1p
 
Sonar qube
Sonar qubeSonar qube
Sonar qube
 
Microservices Architecture for Web Applications using Amazon AWS Cloud
Microservices Architecture for Web Applications using Amazon AWS CloudMicroservices Architecture for Web Applications using Amazon AWS Cloud
Microservices Architecture for Web Applications using Amazon AWS Cloud
 

Similar to MUC - Moodle Universal Cache

Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
Ulf Wendel
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Fabien Potencier
 
Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3
Fabien Potencier
 
CHI-YAPC-2009
CHI-YAPC-2009CHI-YAPC-2009
CHI-YAPC-2009jonswar
 
Caching in WordPress
Caching in WordPressCaching in WordPress
Caching in WordPress
Tareq Hasan
 
Drupal 7 Queues
Drupal 7 QueuesDrupal 7 Queues
Drupal 7 Queues
Philip Norton
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Fabien Potencier
 
Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201Fabien Potencier
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010Fabien Potencier
 
Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010Fabien Potencier
 
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Fabien Potencier
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
Yoshiki Kurihara
 
Lazy evaluation drupal camp moscow 2014
Lazy evaluation drupal camp moscow 2014Lazy evaluation drupal camp moscow 2014
Lazy evaluation drupal camp moscow 2014
Evgeny Nikitin
 
Caching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment CachingCaching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment Caching
Erick Hitter
 
Intro to advanced caching in WordPress
Intro to advanced caching in WordPressIntro to advanced caching in WordPress
Intro to advanced caching in WordPress
Maor Chasen
 
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
andrewnacin
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7chuvainc
 
Speed Things Up with Transients
Speed Things Up with TransientsSpeed Things Up with Transients
Speed Things Up with Transients
Cliff Seal
 
mysqlnd query cache plugin: user-defined storage handler
mysqlnd query cache plugin: user-defined storage handlermysqlnd query cache plugin: user-defined storage handler
mysqlnd query cache plugin: user-defined storage handler
Ulf Wendel
 

Similar to MUC - Moodle Universal Cache (20)

Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3
 
Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3
 
CHI-YAPC-2009
CHI-YAPC-2009CHI-YAPC-2009
CHI-YAPC-2009
 
Caching in WordPress
Caching in WordPressCaching in WordPress
Caching in WordPress
 
Drupal 7 Queues
Drupal 7 QueuesDrupal 7 Queues
Drupal 7 Queues
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
 
Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010
 
Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
Lazy evaluation drupal camp moscow 2014
Lazy evaluation drupal camp moscow 2014Lazy evaluation drupal camp moscow 2014
Lazy evaluation drupal camp moscow 2014
 
Caching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment CachingCaching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment Caching
 
Intro to advanced caching in WordPress
Intro to advanced caching in WordPressIntro to advanced caching in WordPress
Intro to advanced caching in WordPress
 
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
Speed Things Up with Transients
Speed Things Up with TransientsSpeed Things Up with Transients
Speed Things Up with Transients
 
mysqlnd query cache plugin: user-defined storage handler
mysqlnd query cache plugin: user-defined storage handlermysqlnd query cache plugin: user-defined storage handler
mysqlnd query cache plugin: user-defined storage handler
 

More from Tim Hunt

Writing better Behat tests
Writing better Behat testsWriting better Behat tests
Writing better Behat tests
Tim Hunt
 
What’s next for the Quiz and Question bank and for Moodle community collabora...
What’s next for the Quiz and Question bank and for Moodle community collabora...What’s next for the Quiz and Question bank and for Moodle community collabora...
What’s next for the Quiz and Question bank and for Moodle community collabora...
Tim Hunt
 
Question bank improvements in Moodle 4.0 : A successful community collaboration
Question bank improvements in Moodle 4.0 : A successful community collaborationQuestion bank improvements in Moodle 4.0 : A successful community collaboration
Question bank improvements in Moodle 4.0 : A successful community collaboration
Tim Hunt
 
Looking after the Open University's Moodle
Looking after the Open University's MoodleLooking after the Open University's Moodle
Looking after the Open University's Moodle
Tim Hunt
 
Embedding questions anywhere in Moodle
Embedding questions anywhere in MoodleEmbedding questions anywhere in Moodle
Embedding questions anywhere in Moodle
Tim Hunt
 
Hosting STACK at scale
Hosting STACK at scaleHosting STACK at scale
Hosting STACK at scale
Tim Hunt
 
Moodle questions without the quiz
Moodle questions without the quizMoodle questions without the quiz
Moodle questions without the quiz
Tim Hunt
 
2017 UK/IE MoodleMoot: What makes a good moodle quiz? Lessons from the Open U...
2017 UK/IE MoodleMoot: What makes a good moodle quiz? Lessons from the Open U...2017 UK/IE MoodleMoot: What makes a good moodle quiz? Lessons from the Open U...
2017 UK/IE MoodleMoot: What makes a good moodle quiz? Lessons from the Open U...
Tim Hunt
 
I wish I could believe you: the frustrating unreliability of some assessment ...
I wish I could believe you: the frustrating unreliability of some assessment ...I wish I could believe you: the frustrating unreliability of some assessment ...
I wish I could believe you: the frustrating unreliability of some assessment ...
Tim Hunt
 
Hosting Moodle at the OU
Hosting Moodle at the OUHosting Moodle at the OU
Hosting Moodle at the OU
Tim Hunt
 
The Moodle quiz at the Open University
The Moodle quiz at the Open UniversityThe Moodle quiz at the Open University
The Moodle quiz at the Open University
Tim Hunt
 
The Moodle Quiz at the Open University: how we use it & how that helps students
The Moodle Quiz at the Open University: how we use it & how that helps studentsThe Moodle Quiz at the Open University: how we use it & how that helps students
The Moodle Quiz at the Open University: how we use it & how that helps students
Tim Hunt
 
2012 Computer-Assisted Assessment
2012 Computer-Assisted Assessment2012 Computer-Assisted Assessment
2012 Computer-Assisted Assessment
Tim Hunt
 
Moodle’s building blocks for eAssessment tools
Moodle’s building blocks for eAssessment toolsMoodle’s building blocks for eAssessment tools
Moodle’s building blocks for eAssessment tools
Tim Hunt
 
A basic introduction to the Moodle architecture
A basic introduction to the Moodle architectureA basic introduction to the Moodle architecture
A basic introduction to the Moodle architecture
Tim Hunt
 

More from Tim Hunt (15)

Writing better Behat tests
Writing better Behat testsWriting better Behat tests
Writing better Behat tests
 
What’s next for the Quiz and Question bank and for Moodle community collabora...
What’s next for the Quiz and Question bank and for Moodle community collabora...What’s next for the Quiz and Question bank and for Moodle community collabora...
What’s next for the Quiz and Question bank and for Moodle community collabora...
 
Question bank improvements in Moodle 4.0 : A successful community collaboration
Question bank improvements in Moodle 4.0 : A successful community collaborationQuestion bank improvements in Moodle 4.0 : A successful community collaboration
Question bank improvements in Moodle 4.0 : A successful community collaboration
 
Looking after the Open University's Moodle
Looking after the Open University's MoodleLooking after the Open University's Moodle
Looking after the Open University's Moodle
 
Embedding questions anywhere in Moodle
Embedding questions anywhere in MoodleEmbedding questions anywhere in Moodle
Embedding questions anywhere in Moodle
 
Hosting STACK at scale
Hosting STACK at scaleHosting STACK at scale
Hosting STACK at scale
 
Moodle questions without the quiz
Moodle questions without the quizMoodle questions without the quiz
Moodle questions without the quiz
 
2017 UK/IE MoodleMoot: What makes a good moodle quiz? Lessons from the Open U...
2017 UK/IE MoodleMoot: What makes a good moodle quiz? Lessons from the Open U...2017 UK/IE MoodleMoot: What makes a good moodle quiz? Lessons from the Open U...
2017 UK/IE MoodleMoot: What makes a good moodle quiz? Lessons from the Open U...
 
I wish I could believe you: the frustrating unreliability of some assessment ...
I wish I could believe you: the frustrating unreliability of some assessment ...I wish I could believe you: the frustrating unreliability of some assessment ...
I wish I could believe you: the frustrating unreliability of some assessment ...
 
Hosting Moodle at the OU
Hosting Moodle at the OUHosting Moodle at the OU
Hosting Moodle at the OU
 
The Moodle quiz at the Open University
The Moodle quiz at the Open UniversityThe Moodle quiz at the Open University
The Moodle quiz at the Open University
 
The Moodle Quiz at the Open University: how we use it & how that helps students
The Moodle Quiz at the Open University: how we use it & how that helps studentsThe Moodle Quiz at the Open University: how we use it & how that helps students
The Moodle Quiz at the Open University: how we use it & how that helps students
 
2012 Computer-Assisted Assessment
2012 Computer-Assisted Assessment2012 Computer-Assisted Assessment
2012 Computer-Assisted Assessment
 
Moodle’s building blocks for eAssessment tools
Moodle’s building blocks for eAssessment toolsMoodle’s building blocks for eAssessment tools
Moodle’s building blocks for eAssessment tools
 
A basic introduction to the Moodle architecture
A basic introduction to the Moodle architectureA basic introduction to the Moodle architecture
A basic introduction to the Moodle architecture
 

Recently uploaded

Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 

Recently uploaded (20)

Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 

MUC - Moodle Universal Cache

  • 3. What is a cache A place to keep data that would take time to re-compute A cache stores values identified by a key E.g. list of activities in a course, stored by course id Caches may get purged at any time Cannot store real data there, just derived values for performance
  • 4. Why have a cache system? Developers want to do stuff with data, not re-implement caching Want to be able to use different back-end stores Disc, Memcache, REDIS, … cachestore_ is a plugin type Admins should control which data goes in which store
  • 5. Cache performance Typical call to cache::get For a typical page • 0.5 ms data fetched from Memcache 150 • 0.05 ms data in static acceleration 700 For comparison: typical DB query • 3 ms 40
  • 7. Typical use $cache = cache::make('core', 'string'); $strings = $cache->get($component); if ($strings === false) { $strings = load_strings($component); $cache->set($component, $strings); }
  • 8. Defining your cache In db/caches.php in your plugin. E.g. from lib/db/caches.php $definitions = array( // Used to store processed lang files. // Keys used are revision, lang and component of the string file. // Static acceleration size is based on student access of the site. 'string' => array( 'mode' => cache_store::MODE_APPLICATION, 'simplekeys' => true, 'simpledata' => true, 'staticacceleration' => true, // Metadata helps cache 'staticaccelerationsize' => 30, // system handle the data 'canuselocalstore' => true, // efficiently. ), ); $string['cachedef_string'] = 'Language string cache';
  • 9. Types of cache Application – Data that applies throughout Moodle E.g. list of activities in each course / language strings Session – Data that is relevant while a user is logged in E.g. list of all course categories this user can access Request – Data within the handling of one request E.g. list of temporary tables
  • 10. Clearing the cache $cache = cache::make('core', 'questiondata'); $cache->delete($questionid); cache::make('core', 'questiondata')->purge(); Recommended: just clear out what has changed Dangerous Also not recommended: time-to-live in cache definition
  • 11. Bulk actions $cache->get_many(['key1', 'key2']); // ['key1' => 'value1', 'key2' => 'value2'] $cache->set_many( ['key1' => 'value1', 'key2' => 'value2']); $cache->delete_many(['key1', 'key2']);
  • 13. Data source: why? Avoids the normal “is this in the cache? Yes: good; No, re-compute” Tell the cache where to get the data if it is not yet stored
  • 14. Data source: definition $definitions = array( // Cache for question definitions. This is used by the question // bank class. Users probably do not need to know about this cache. // They will just call question_bank::load_question. 'questiondata' => array( 'mode' => cache_store::MODE_APPLICATION, 'simplekeys' => true, // The id of the question is used. 'requiredataguarantee' => false, 'datasource' => 'question_finder', 'datasourcefile' => 'question/engine/bank.php', ), )
  • 15. class question_finder implements cache_data_source { public static function get_instance_for_cache(cache_definition $definition) { return self::get_instance(); // Singleton pattern. } public function load_for_cache($questionid) { global $DB; $questiondata = $DB->get_record_sql('SELECT q.*, qc.contextid FROM {question} q JOIN {question_categories} qc ON q.category = qc.id WHERE q.id = :id', array('id' => $questionid), MUST_EXIST); get_question_options($questiondata); return $questiondata; } } Data source: use $cache = cache::make('core', 'questiondata'); $cache->get($questionid);
  • 16. Data source: implementation public function get($key, $strictness = IGNORE_MISSING) { // ... $result = $this->store->get($key); // ... if ($result === false) { if ($this->loader !== false) { $result = $this->loader->get($key); } else { if ($this->datasource !== false) { $result = $this->datasource->load_for_cache($key); } } } // ... }
  • 23. Memcache purging MUC lets you store many different caches in one backend cache::purge(); should just clear one of those caches With Memcache, cache::purge() wipes all caches This is one of the reasons the VLE crashed in October Moodle 3.2 now has REDIS cache store in core We should consider switching
  • 24. Complex keys MUC tries to support keys that are not just ints or strings However this hurts performance – best not to use it This probably applies to other advanced MUC features Caching is about performance Simple is good
  • 25. Automated tests MUC caches are automatically cleared between each unit test or Behat test