Like button in my codeigniter website |
(08-20-2015, 03:34 PM)sebastianvirlan Wrote: On this category method I have parameters like: This is why code should be optimized based on your requirements and analysis of the application. If it doesn't make sense to use database caching for this purpose on these pages, then don't use it. You didn't include this information in your original question. Database caching isn't your only option for caching the data, either. You could use the cache library to store the number of likes separately from the database cache that handles the rest of the data on the page(s). In the worst case, you could probably figure out a method of deleting the correct file for the query if you have to use database caching, but it's not something supported by CI directly. My point with the minimum age on the cache was this: if you write to the database but only cache the value in the database when the cache is stale, the value in the database will be correct but the value in the cache may be incorrect for a short amount of time. To make sure the cached value doesn't corrupt the database value in the update, you use something like this in your update SQL: Code: UPDATE table_likes SET column_likes = column_likes + 1 where id = 2 So, instead of adding one to the cached value and setting that value in an update statement, you tell the database to set the column's value to the current value + 1, and you still don't have to query the database to get the value. |
Messages In This Thread |
Like button in my codeigniter website - by sebastianvirlan - 08-19-2015, 03:20 PM
RE: Like button in my codeigniter website - by mwhitney - 08-20-2015, 08:25 AM
RE: Like button in my codeigniter website - by sebastianvirlan - 08-20-2015, 03:34 PM
RE: Like button in my codeigniter website - by mwhitney - 08-24-2015, 07:58 AM
|