Skip to content

Instantly share code, notes, and snippets.

@dougblackjr
Created July 21, 2020 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dougblackjr/db60eb2f77973fc52ea1651c4b68ca18 to your computer and use it in GitHub Desktop.
Save dougblackjr/db60eb2f77973fc52ea1651c4b68ca18 to your computer and use it in GitHub Desktop.
Caching Inside a CraftCMS Plugin
<?php
// To cache a variable
// function add($key, $value, $secondsToCache)
\Craft::$app->getCache()->add(
$nameOfCacheKey,
$valueToCache,
$numberOfSecondsToCache
);
// To retrieve the cache
// function get($key)
// Will return false if the cache is not available, or the cache has expired
$myCachedObject = \Craft::$app->getCache()->get($nameOfCacheKey);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment