title: General/Phalcon - ACL and Database Storage
body: <p><strong>Background</strong></p>
  
  <p>I'm currently working on a Phalcon application. The application itself is relatively simple, but I am using it as a tool to learn about some more advanced concepts and techniques.</p>
  
  <p>I've ditched my homebrew ACL (access-control list) solution, and plumped for the ACL provided in Phalcon.</p>
  
  <p>This question is more conceptual, as I would feel confident in implementing any solution.</p>
  
  <p><strong>Question</strong></p>
  
  <p>The question is this:
  "Where do you store the information on your ACL?"</p>
  
  <p><strong>Possible Solution</strong></p>
  
  <p>I currently have a static array, that I fill up with the various actions and the access level of them.</p>
  
  <p>I feel that this is slightly limiting, and would potentially be better served, through a database storage.</p>
  
  <p>I could use a bitmask, to indicate the user roles that are allowed access to the various resources, or maybe a minimum level.</p>
  
  <p>The other problem I have, is that it is hierarchical (to an extent) but multiple roles could exist - with slightly different permissions.</p>
  
  <pre><code>eg. 
  Admin has all roles of captain, secretary and user.
  Captain has all the roles of a user and the ability to pick players.
  Secretary has all the roles of a user and contact the opponent's secretary.
  Captain and secretary both have the ability to email players.
  </code></pre>
  
  <p>Imagine it as somewhat of a <em>Venn diagram</em> of permissions, if you will.</p>
  
  <p><strong>Caching</strong></p>
  
  <p>The next issue, would be that the accessing of the database every time, would add a performance overhead, so I guess caching it would make sense.</p>
  
  <p>The issue would then come, how to invalidate the cache (there are only two hard things in computer science...)... maybe there could be a database field that had an md5 hash of the ACL, which was checked against on page-load, to see if it needs to reload the ACL information.</p>