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 7536927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:42:34+00:00 2026-05-30T06:42:34+00:00

I’m trying to cache JSON content generated by a php script from database. However

  • 0

I’m trying to cache JSON content generated by a php script from database. However the dataset is very stable, there are very few changes or additions. Meaning data could go unchanged for weeks.
The issue is that it contains a LOB column and that just takes a noticeable time to load, longer compared to supplying the json from a text file meaning git is the actual database call that makes it slow.

I’m displaying the data in a table with pagination(datatables jquery plugin) and for each page change the data is fetched from database again, also when going back to the previous page.

I’ve tried following:

"beforeSend": function (request)
{
    request.setRequestHeader("cache-control", "max-age=86400");
},

Does not work.

I tried mod_expires:

ExpiresActive On
ExpiresDefault "access plus 4 hours"
ExpiresByType application/javascript "access plus 1 day"
ExpiresByType application/json "access plus 1 day"

Does not work.

Therefore I assume all these settings are for real files on the file system only and not for dynamic generated stuff?

I would prefer a configurable approach meaning using Apache/PHP since I will not have full control over the server.

EDIT BEFORE FIRST ANSWER:

Note that the JSON contains multiple records so a key/value store would be kind of difficult to avhieve. The key would have to contain a lot of stuff: Query/filter expression and the requested page for paging.

EDIT 2:

Development and prod. are Windows… so memcached is not really an option…

EDIT 3:

I’ve tried kristovaher solution but does not work. The cache headers are not in the response all the time and after some plaing around I believe I determined the issue:
I’m required do use NTLM authentication and when doing 2 request shortly after each other it works fine, however if you wait a bit, it seems the user is re-authenticated and then the cache control header is “lost”.

  • 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-30T06:42:35+00:00Added an answer on May 30, 2026 at 6:42 am

    I’ve played around a bit and come to the conclusion that caching with client side and using headers does not seem to work in my case. Maybe I’m doing it wrong, maybe it is the way my application works or web server config.

    Anyway my solution was to use APC:

    http://www.php.net/manual/en/book.apc.php

    I’m using windows, the appropriate binaries can be found here:

    http://downloads.php.net/pierre/

    which one depends on your PHP version and how it was compiled (with vc6 or vc9).
    The php_apc.dll will need to be put in your php extension directory and you will need to add the line

    extension=php_apc.dll 
    

    to the php.ini

    Then you bascially do:

    if (apc_exists($key)){
       return apc_fetch($key);
    }
    // get data from database because it was not in the cache
    //...
    //add data to cache
    apc_add($key, $result);
    

    If data on my page is uncached it took around 1-2s to load. Well thats not bad but feels very laggy. if data is in cache it is more like 20-30ms. of course this difference is very noticeable.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I would like to count the length of a string with PHP. The string

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.