Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3847494
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:33:37+00:00 2026-05-19T16:33:37+00:00

I am looking for more detailed information on how I can get the following

  • 0

I am looking for more detailed information on how I can get the following caching behavior in Drupal 7.

I want a block that renders information I’m retrieving from an external service. As the block is rendered for many users I do not want to continually request data from that service, but instead cache the result. However, this data is relatively frequent to change, so I’d like to retrieve the latest data every 5 or 10 minutes, then cache it again.

Does anyone know how to achieve such caching behavior without writing too much of the code oneself? I also haven’t found much in terms of good documentation on how to use caching in Drupal (7), so any pointers on that are appreciated as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:33:38+00:00Added an answer on May 19, 2026 at 4:33 pm

    The functions cache_set() and cache_get() are what you are looking for. cache_set() has an expire argument.

    You can use them basically like this:

    <?php
    if ($cached_data = cache_get('your_cache_key')) {
      // Return from cache.
      return $cached_data->data;
    }
    
    // No or outdated cache entry, refresh data.
    $data = _your_module_get_data_from_external_service();
    // Save data in cache with 5min expiration time.
    cache_set('your_cache_key', $data, 'cache', time() + 60 * 5);
    return $data;
    ?>
    

    Note: You can also use a different cache bin (see documentation links) but you need to create a corresponding cache table yourself as part of your schema.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a more versatile way to get from a data.frame to
Looking for more detailed info on how to read the NAL header and more
I am looking at collecting more detailed java statistics (in plain text format) i.e.
I'm looking for alternatives to Google Book Search API. Ideally, something with more detailed
I'm looking to see if more of the seasoned web service veterans can comment
I am looking for more advanced alternatives to xsd.exe . I am just about
I am making my first text field, and I am looking for more of
I've found a similar question here , but I'm looking for more general solutions.
I am looking for a more elegant solution to formatting a MAC address with
I am looking for a more efficient way to do comparisons between all elements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.