updating the page permissions not working properly

Permalink
I'm setting the permission for page view programmatically, but it is working only for initial update, further updates not reflecting properly.

Here is my code snippet
$page = Page::getByID($cID);
if (in_array('Public', $groups)) {
    $pxml->guests['canRead'] = true;
} else {
    $pxml->guests['canRead'] = false;            
    for ($i=0; $i<count($groups); $i++) {
        $grp = $this->getGroupObj($groups[$i]);
        $pxml->group[$i]['gID'] = $grp->gID;
        $pxml->group[$i]['canRead'] = true;            
    }
}
$page->assignPermissionSet($pxml);


I have checked database for page permission, it is updating properly, but page view is not working based on the updated permissions.

If I set permission through front end UI, then it is working properly.

Is it because of permission cache?

Can anybody tell me how to clear the page permissions cache, or am I missing anything in the code.

Thanks,
Bala

 
kumarbalap replied on at Permalink Reply
got it working, below code did the trick

$page->refreshCache();
Cache::delete("page_permission_set_guest", $cID);