简体   繁体   中英

php cache or anything which can reduce database query on page refresh

hello all i am having a website where i have a side pannel which is displaying the same thing on all the pages i mean the data which is fetched by the database dosent change often. like i have a pannel on the left side of my site which is displaying recent birthdays which is going to be change after 1 day only but the problem is that everytime the page is refreshed the same data needs to be fetched from the database again and again which can increase the database load and also page load time

i was wondering if there is anything which can display the side bar once the query is executed and after that the result will be fetched from session/cache or what ever the sollution is

i think it can be done by cache like memcache but i dont know how i also tried to store them into session and cookies but there is error it say can not store objects into session and also i have to use loop to the results obtained by query the query is like

  $birthday_query=mysqli_query($connection,"select name,email,id,date from members where dob 'some code here' "); 
   // this code fetches about 30-40 results and i am using the loop to display the results..

Yes, you can use memcache to store the information. This is your best option as it is going to stay in the server memory.

You can also use something very simple like a temp file where to keep the recent birthdays information - the HTML code. Update the information in this file once a day and read it from there. For every user you can read the information once (when they first come the website) and then store it and read it from the session.

For just 30-40 results, you don't need caching it will not add a great value, good will be to use Session to store the data as soon user browse your first page and then fetching data always from Session . using a file to cache html is also a good bet here.

you can check how to store object into session

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM