Skip to content
Snippets Groups Projects
Select Git revision
  • 1ea33ff36bf70ee2099f8d225f488dc220e3bcff
  • master default protected
2 results

filecache.php

Blame
  • filecache.php 13.37 KiB
    <?php
    
    /**
    * @author Robin Appelman
    * @copyright 2011 Robin Appelman icewind1991@gmail.com
    *
    * This library is free software; you can redistribute it and/or
    * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
    * License as published by the Free Software Foundation; either
    * version 3 of the License, or any later version.
    *
    * This library is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
    *
    * You should have received a copy of the GNU Affero General Public
    * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
    *
    */
    
    /**
     * provide caching for filesystem info in the database
     *
     * not used by OC_Filesystem for reading filesystem info,
     * instread apps should use OC_FileCache::get where possible
     *
     * It will try to keep the data up to date but changes from outside ownCloud can invalidate the cache
     */
    class OC_FileCache{
    	/**
    	 * get the filesystem info from the cache
    	 * @param string path
    	 * @param string root (optional)
    	 * @return array
    	 *
    	 * returns an associative array with the following keys:
    	 * - size
    	 * - mtime
    	 * - ctime
    	 * - mimetype
    	 * - encrypted
    	 * - versioned
    	 */
    	public static function get($path,$root=false){
    		if(OC_FileCache_Update::hasUpdated($path,$root)){
    			if($root===false){//filesystem hooks are only valid for the default root
    				OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path));
    			}else{
    				OC_FileCache_Update::update($path,$root);
    			}
    		}
    		return OC_FileCache_Cached::get($path,$root);
    	}
    
    	/**
    	 * put filesystem info in the cache
    	 * @param string $path
    	 * @param array data
    	 * @param string root (optional)
    	 *
    	 * $data is an assiciative array in the same format as returned by get
    	 */
    	public static function put($path,$data,$root=false){
    		if($root===false){
    			$root=OC_Filesystem::getRoot();
    		}
    		$path=$root.$path;
    		$parent=self::getParentId($path);
    		$id=self::getId($path,'');