Skip to content

WP Packages is our new WPackagist replacement that's 17x faster and updates every 5 minutes

Acorn

Roots is an independent open source org, supported only by developers like you. We’ve been improving the WordPress developer experience since 2011, and your support keeps it independent.

Laravel Cache as an Alternative to WordPress Transients

View as Markdown:

Acorn provides Laravel integration with WordPress, which means that certain Laravel components are able to be used within your WordPress site.

Compared to WordPress transients API, Laravel Cache provides a more standardized and developer-friendly approach to caching data. It also has a wider range of cache storage options, compared to the WordPress Transients API, which only supports storing data in the WordPress database.

Review the Laravel Cache docs to get a more detailed understanding about how it works, along with the various ways that the cache can be configured

Storing data in the cache

use Illuminate\Support\Facades\Cache;

Cache::put('key', 'value', $minutes);

Retrieving data from the cache

use Illuminate\Support\Facades\Cache;

$value = Cache::get('key');

Removing items from the cache

use Illuminate\Support\Facades\Cache;

Cache::forget('key');

You can also use Acorn's WP-CLI integration to interact with the cache:

$ wp acorn cache:clear

Last updated