I'm building an online shop & trying to improve performance by minimising MYSQL queries.
Is it good practice to cache the mysql queries via a txt file and then fetch that instead of the query? This is what I'm doing"
- A php class takes the sql query as a string
- does an md5 of it
- if this is the first time it's run
- then perform the query on the database
- get the results in an array
- serialize the array and store it as md5_Of_Query.txt
- return either unserialize(file_get_contents(md5_of_Query.txt)) or $results of actual query, depending on whether or not the cache exists and is valid.
- The class also checks the filemtime() of the txt file and if its greater than say, one hour old, then re-perform the query and refresh the cache.
Is this more efficient than doing sql queries every time? Any security issues I'm missing?