cache

Drupal Logo

Drupal 8: Custom Cache Bins

14th September 2019 - 10 minutes read time

Drupal's cache system is robust, feature full and extensible. It can be used to cache small blocks of rendered output or the results of more complex calculations. The cache can be stored in a for the page request, in a database or in a different cache system.

I recently needed to store a decent amount of data that was pulled from an API. Getting the data from the API took a few seconds so it was important to cache this within the site for quick retrieval. Even just storing the cache in the database was many times quicker than the API so it made sense to cache the results within the site. Having the user sat there waiting for the page to load every time they do anything isn't great.

To this end I created a small Drupal service that would manage this cache for me. Here is the record from the services YAML file within the module.

Drupal Logo

Drupal 8 : How To Avoid Block Caching

11th February 2018 - 5 minutes read time

I was struggling with a problem on a Drupal 8 project that was in development recently where a block used to show information to anonymous users was cached for the first user who saw it. This meant that the special message meant for the first user was then being seen by all subsequent users who visited that page. This only happened when page caching was turned on, but as it's best practice to do that I didn't want to turn that off just to solve one little problem.

Drupal Logo

Getting Started With Cache Functions In Drupal 7

30th March 2015 - 14 minutes read time

When generating markup in Drupal you'll often want to store the output in a cache instead of regenerating it every time. This is especially important for potentially expensive rendering tasks that don't change between page requests. Drupal 7 comes with a cache system that can be taken advantage of with the cache_get() and cache_set() functions. There is also a third function called drupal_static() that also fills in gaps between these two functions.

PHP Logo

Simple PHP Code To Get last.fm Last Played Tracks

1st December 2011 - 5 minutes read time

The other day I was approached by a friend (Julie Cheung) and asked if I could create some code that would display a list of last played tracks from last.fm. Julie isn't a PHP developer and so the code I gave her had to be easily understandable so that she could edit it herself if needed. The following code is what I came up with.