Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rotaercz's avatar

I have a database table that gets updated every 2-3 months or so. Is there a good way to not have to query the database when it hasn't changed?

I have a database table that gets updated every 2-3 months or so. Is there a good way to not have to query the database when it hasn't changed?

I'm just working on making my site more efficient and faster. Is there a good way to handle cases like this?

0 likes
6 replies
jlrdw's avatar

Is there a good way to not have to query the database when it hasn't changed?

  • Is it just an archive database
  • Does the public have access to it
  • No use case given
  • Very vague question

But I guess take down the site and never use the data, then no queries would be necessary.

Cronix's avatar
Cronix
Best Answer
Level 67

A perfect scenario for caching the queries. You can set a time limit on how long the cache is remembered for, or you could invalidate the cache whenever you add/change data.

You can even cache the whole page (view) if you want and not really hit laravel at all unless the data changes.

https://laravel.com/docs/5.6/cache

Here's a good series to watch as well: https://laracasts.com/series/learn-laravel-and-redis-through-examples

1 like
rotaercz's avatar

That's really helpful. I'll check caching out.

jlrdw's avatar

@Cronix a queston on your answer:

As example say it is a site like pet supplies.

You have hundreds of searches daily, making each query different, at least most.

I may type in a search for Food A, another types in cat food a, another types just a portion fragment, depending on like clause, etc.

Are you saying to cache and hold all previous variations of queries until released?

Cronix's avatar

@jlrdw I don't think caching really fits well in that scenario where it's performing a user search, which could be different each time. I mean you could, but I'd probably use a low cache time like 10 minutes.

For the OP's question, where the data doesn't change for months at a time, caching sounds like a great option. For a "user search" type thing, I'd probably hand that off to Algolia or something. They have some great voodoo magic that is, well, fast.

Please or to participate in this conversation.