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

  • Home
  • SEARCH
  • 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 346271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:09:41+00:00 2026-05-12T11:09:41+00:00

Is it better (more efficient, faster, more secure, etc) to (A) cache data that

  • 0

Is it “better” (more efficient, faster, more secure, etc) to (A) cache data that is used on every page load in the $_SESSION array (but still querying a table for a flag to reload the data fresh), or (B) to load it from the database each time?

I’m using the cache method (A), but I’m worried that with hundreds of users, memory could become an issue? It’s just simple data, like firstname, lastname, birthday, etc.

With either method, there’s still a query being run. Thoughts?

  • 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-12T11:09:41+00:00Added an answer on May 12, 2026 at 11:09 am

    If your data is used on every pages, and is the same for all users, I wouldn’t cache it in $_SESSION (which means having a different copy of that data for each user), but with another mecanism, like :

    • file
    • In memory, with APC for instance (if only 1 server)
    • In memory, with memcached, for instance (if you have several servers)
    • If your data requires long calculations or several DB queries to be obtained, caching it in database could be another possibility (would mean only 1 query to fetch back, and less calculations)

    If your data is not the same for each user (which seems to be the case in your situation, as you are caching names, birthdates, …) :

    • I would make sure I only cache what is necessary
    • Once you only have a few data to cache, putting it in session should be quite OK
    • If you really have that many users, you’ll probably have some other scalability problems, and will most likely come to use something like memcached anyway ; which means you’ll have some other way of caching 😉

    As a sidenote : if you are doing the same query over and over again, you DB server should cache it by itself (for MySQL, it would go into the “query cache“) ; so, it would not be as bad as you think, I suppose — even if not that much optimized ^^

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

Sidebar

Related Questions

Which is the more efficient/faster/better way to check if a key exists? if 'subject'
I was wondering which is a better/faster/more efficient way of turning arbitrary strings into
Is there a better, more elegant (and/or possibly faster) way than boolean isNumber =
Or better said: When to use array as a field data type in a
I'm looking for more and better documentation about snapshots, flow repositories, and flow state
Is one more preferred, or performs better over the other?
Is there a better, more jQuery-ish way of handling this image substitution? var image
Give me some of your thoughts on which is a better coding practice/makes more
What is a more efficient methods for drawing circles on a canvas. I can
I have some content on my page that I require to be loaded via

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.