dps57553 2015-05-30 13:22
浏览 64

php和mysql - 避免缓存

I have a problem that one of my users, make an insert into my mysql database, but when he goes to another page to list these inserts, it only return old data that was previous there. He can only see the changes after several minutes or even hours.

I read that If I add a random number in my url, I can avoid cache, but still not working.

I tried to put these headers on php.

header("Cache-Control: private, no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

And I tried this one too:

SELECT SQL_NO_CACHE...

None work. Still don't get any visible changes.

  • 写回答

1条回答 默认 最新

  • dsh1956 2015-05-30 13:46
    关注

    Try using the Expires headers in your htaccess file. You will need to ask your user to Ctrl+F5 (Force refresh) for it to correctly take effect;

    <IfModule mod_expires.c>
        ExpiresActive on
        ExpiresByType text/html "access plus 0 seconds"
    </IfModule>
    

    This will tell the browser not to cache the text and html within that directory and any subdirectories (unless otherwise specified). I had a similiar issue and resolved it with this when I realised my caching was affecting the update of live data.

    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示