title: CakePHP and pessimistic locking: database vs cache
body: <p>I've implemented a <strong>pessimistic locking</strong> 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.</p>
  
  <p>Overall, the query are:</p>
  
  <ul>
  <li>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));</li>
  <li>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));</li>
  </ul>
  
  <p>I'm wondering whether I should use the <strong>Cache</strong> 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).</p>