开发者

Quick Cache Solution PHP

开发者 https://www.devze.com 2023-04-04 14:47 出处:网络
I am setting up a vehicle reg lookup system that matches to products. The data we receive from the lookup company we can only store for 24 hours. I think storing it in the database might be too much t

I am setting up a vehicle reg lookup system that matches to products. The data we receive from the lookup company we can only store for 24 hours. I think storing it in the database might be too much tr开发者_StackOverflowouble. It is a shared 1and1 account. I was thinking of using PHP Sessions and just storing it as an array in the session using the registration plate as the session id.

That way the garbage collector should ensure I don't keep it for more than 24 hours. Will this work and are there any draw backs?


Sessions are unique to each client interacting with the site. A client can only access information it puts in sessions, not anyone elses. So session wouldn't work in this case. I would say use memcache, but you probably can't do that on a shared 1and1 account. I would recommend the database with an "expires" field. You can setup a cron to run periodically (i.e. every 15 minutes) to delete records that have expired.


As Brent has posted, it would be best to store it in database with a timestamp and run a cron periodically to remove expired entries.

But if you don't want to use database you can also store the retrieved data into simple files in a folder.

Just make filenames as the Registration numbers and store the data in it. Then in the cron you can check the filemtime and delete files older than 24 hours.

One thing to note with filemtime is that the file info is cached by PHP. So if you re-retrieve the data and simple modify the file data (instead of deleting and the recreating the file), old mtine would be returned. To avoid this use clearstatcache in your cron as well as in your script if you update data for an existing file.


Store data in mysql database and for caching check Varnish or Squid

0

精彩评论

暂无评论...
验证码 换一张
取 消