Twitter Feed

Xataface Maillist

Sign up to receive the Xataface news letter with weekly updates and development tips.

Found 1 of 139 records in table Wiki
Now Showing 1 of 1

Current Record: Cached_permissions

Cached Permissions


Cached Permissions


When you insert a SQL query in your getPermissions function, this will slow down the app dramatically because this function is called by each query. To resolve this problem, it is better to use cached permissions in your /conf/ApplicationDelegate.php or table/table.php.


Here is an example :
class tables_mytable {

    private $cachedPerms = null;
    private function _getCachedPerms($param1, $param2, ..., $paramN){
        if ( !isset($this->cachedPerms) ) {
            $this->cachedPerms = array();
            // do some stuff
            $res = mysql_query("select * from foo where bar=1 and param2='".addslashes($param2)."'");
            while ( $row = mysql_fetch_assoc($res) )  $this->cachedPerms[$row['fooid']] = $row;
        return $this->cachedPerms;

    function getPermissions($record){
        // do some stuff
        $perms = $this->getCachedPerms($param1, $param2, ..., $paramN);
        return $perms;
Here, getPermissions() will run a db query on its first request, but subsequent requests will just load the cached value.
blog comments powered by Disqus
Powered by Xataface
(c) 2005-2021 All rights reserved