Drupal 6


Recently I needed to implement caching for a custom Drupal module. I needed my module to cache exactly every 30 minutes on the hour and half-hour.

After doing my homework, I found the necessary Drupal functions in cache_get() and cache_set().

Additionally, I found a good warning in this Civic Actions blog post (Drupal Gotchya: Cache_get() Returns Expired Items) about Drupal relying on cron to determine whether a cache has expired.

The best way to handle caching the way you want is to write some custom wrapper functions. This will give you the ability to deal with edge cases as you need. Here are my custom cache_get and cache_set functions.

NOTE: This post describes the very simple process of starting a custom module. The purpose is to use this as a basis for all other custom modules created in Drupal 6 or Drupal 7.