1
votes

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).

1
not sure if I understand your question, it's a good idea to use cakephp cache, in your specific case?del_dan
Well, I have to store for 30 seconds that a page is being edited. I'm wondering if using the database it's too much ‘resource expensive’ than just using the simple Cache.entropid
Depending on the number of users is to have temporary tables, but since I do not think you have to edit a cache is appropriate.del_dan

1 Answers

0
votes

You could use Redis for that. It's an in memory key/value storage database and we have used it for full page caching in an application and it works just fine.

For CakePHP 2 there is a Redis Cache Engine in development. Here is an old (havent tested it) cache engine for Cake https://github.com/plastic/redis-cache-cakephp.

There is also a data source for CakePHP2 but I don't remember the link right now, sorry.