#011064: ezcCacheStorageFile::search is visible as private for no discernable reason

Description:

I am trying to create a class that stores and retrieves data from both the filesystem and APC simultaneously. This requires that I extend the ezcCacheStorageFile class and overwrite the the restore, store, and delete functions to insert the mirroring logic for APC and the filesystem.

When I do this I get the following error:
{
Fatal error: Call to private method ezcCacheStorageFile::search() from context 'ezcCacheStorageFileApcArray'
}

Obviously the issue is that the search function is being declared visible as "private." This makes it impossible to overwrite the restore, store, and delete functions since they all rely on searching. The restore, store, and delete functions are all visible as "protected."

In my code example below, nevermind the APC wrapper class I wrote "ApcCache." It is a nearly direct interface to the documented APC functions.


class ezcCacheStorageFileApcArray extends ezcCacheStorageFile
{
    /**
     * Store data to the cache storage.
     * This overrides this function in the storage class. We need to try to store things in APC for the data to keep it close but mirror to the filesystem which is shared over NFS to multiple servers.
     */
    public function store( $id, $data, $attributes = array() ) 
    {
        // Generates the identifier
        $filename = $this->properties['location'] . $this->generateIdentifier( $id, $attributes );
        
        // Deletes the files if it already exists on the filesystem
        if ( file_exists( $filename ) ) 
        {
            if ( unlink( $filename ) === false ) 
            {
                throw new ezcBaseFilePermissionException( $filename, ezcBaseFileException::WRITE, 'Could not delete existsing cache file.' );
            }
        }
        
        // Deletes the data from APC if it already exists
        ApcCache::delete( $filename );
        
        // Prepares the data for filesystem storage
        $dataStr = $this->prepareData( $data );
        
        // Tries to create the directory on the filesystem
        $dirname = dirname( $filename );
        if ( !is_dir( $dirname ) && !mkdir( $dirname, 0777, true ) )
        {
            throw new ezcBaseFilePermissionException( $dirname, ezcBaseFileException::WRITE, 'Could not create directory to stor cache file.' );
        }
        
        // Tries to write the file the filesystem
        if ( file_put_contents( $filename, $dataStr ) !== strlen( $dataStr ) ) 
        {
            throw new ezcBaseFileIoException( $filename, ezcBaseFileException::WRITE, 'Could not write data to cache file.' );
        }
        
        // Tries to set the file permissions
        if ( ezcBaseFeatures::os() !== "Windows" )
        {
            chmod( $filename, $this->options->permissions );
        }
        
        // Prepares the data for APC storage
        $dataObj = $this->prepareData( $data, true );
        $dataObj->mtime = filemtime( $filename );
        
        // Stores it in APC
        ApcCache::store( $filename, $dataObj, $this->properties['options']['ttl'] );
        
        // Returns the ID for no good reason
        return $id;
    }
}


Environment:

PHP Version: 5.2.3


- Attachments

No attachments for this issue.


- Comments

Hello Grady,

I am not sure why you are trying to extend the CacheStorage *File* - storing in APC has nothing to do with files, so perhaps you might want to consider inheriting from ezcCacheStoage: http://ez.no/doc/components/view/latest/(file)/Cache/ezcCacheStorage.htmlurl

However, I sort of agree that this should be a protected method.

regards,
Derick

#252998 by Derick Rethans on July 3rd, 2007 [Permanent Link]

The overall thing I am trying to do is largely irrelevant and distracting. The point is that those methods relating to search are set to private when they probably shouldn't be.

Anyway, I am creating a file system-APC hybrid. This is a very specific and largely uninteresting endeavor. But I need to store on the filesystem and in APC simultaneously to make all reads happen from APC when possible. This is for a situation where the cache directory is shared between many servers using NFS. This whole setup is not recommended but it will hopefully relieve some stress from the filesystem. :)

#253006 by Grady Kuhnline on July 3rd, 2007 [Permanent Link]

Fixed in rev. 6161. It will be available in Cache 1.3alpha1.

#253688 by Alexandru Stanoi on September 17th, 2007 [Permanent Link]

- History
Properties
Type Bug
Priority Medium
Component Components » Cache
Affects Unknown
Fix Versions 1.3alpha1 - Cache 1.3alpha1
2007.2alpha1 - eZ components 2007.2alpha1
Reporter Grady Kuhnline
Responsible Alexandru Stanoi
Status 0 Closed
Resolution Fixed
Created July 3rd, 2007
Updated September 17th, 2007
Resolved September 17th, 2007
 
Navigation [Permanent Link]
Previous Issue
Back to Issues List
Next Issue: #015537
  Graph shows to small and truncated rotated axis labels