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 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

Ask A Question

Stats

  • Questions 220k
  • Answers 220k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes. The 1st level cache is for the session only.… May 12, 2026 at 11:54 pm
  • Editorial Team
    Editorial Team added an answer thanks for the answers... I actually ended up using my… May 12, 2026 at 11:54 pm
  • Editorial Team
    Editorial Team added an answer The correct response is : <s:ElementMenu Name="emBallMenu" VerticalAlignment="Top" ActivationMode="HostInteraction" ActivationHost="{Binding… May 12, 2026 at 11:54 pm

Related Questions

This is a two-part question: First, I am interested to know what the best
In MySQL, is it generally faster/more efficient/scalable to return 100 rows with 3 columns,
Basically I have a custom List class that contains different fruits. Assume that each
If you have a custom collection class that stores the weights of a single

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.