I've implemented a pessimistic locking in my CakePHP application, shared between different Controllers. Basically, when a page is accessed a record is written into a table, indicating that that entry of that model is being edited by that user, with the timestamp. Every 30 seconds, with an ajax call, that timestamp of that record is updated, indicating that the page is still in use. If someone tries to enter the page, the access is denied. If the page is left, the ‘lock’ expires at the end of those 30 seconds.
Overall, the query are:
- 3 when the page is loaded (purge all the lock older than 1 hour (DELETE), check if the page isn't already in use (SELECT) and if it isn't, create the lock (INSERT));
- 2 when the lock is updated (check if the page isn't already locked (SELECT); if it isn't, update the timestamp of the lock (UPDATE));
I'm wondering whether I should use the Cache system, since this isn't a permanent storage of data (which should obviously use the database), but just something temporary. Could it be faster than the database? (but I'm not sure, since my cache is just File cache).