ultimix

- Main Page
- Data Structures
- Files
- Examples

- Data Structures
- Data Structure Index
- Data Fields

Public Member Functions | Data Fields
cache_1_0_0 Class Reference

## Public Member Functions
| __construct ()
| reset ()
| get_data ($SectionOriginName)
| set_data ($SectionOriginName, $Data)
| add_data ($SectionOriginName, $Data, $Tags=array())
| delete_data ($SectionOriginName)
| data_exists ($SectionOriginName)
| delete_data_by_tag ($Tag)
| flush ()
| drop_cache ()
| __destruct ()

## Data Fields
| $Cache
| $Security = false
| $CacheWasUpdated = false
| $TableOfContents = false
| $CacheSwitch = true
| $CacheTimeout = 120

## Detailed Description

Class provides cache manipulating routine.

Author
  Dodonov A.A.

Definition at line 26 of file cache.php.

## Constructor & Destructor Documentation

__construct | ( |  | ) |

Constructor loads cache from file.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 114 of file cache.php.

{
try
{
$this->Security = get_package( 'security' , 'last' , __FILE__ );
$PageName = $this->Security->get_gp( 'page_name' , 'command' , 'default' );
$this->Cache = @file_get_contents( dirname( __FILE__ ).'/data/'.$PageName.'.cache' );
$this->TableOfContents = @file_get_contents( dirname( __FILE__ ).'/data/'.$PageName.'.table' );
if( $this->TableOfContents !== false )
{
$this->TableOfContents = unserialize( $this->TableOfContents );
}
$this->reset();
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

__destruct | ( |  | ) |

Constructor loads cache from file.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 808 of file cache.php.

{
try
{
if( $this->CacheSwitch === false )
{
return;
}
$this->flush();
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

## Member Function Documentation

add_data | ( |  | $SectionOriginName,
|  |  | $Data,
|  |  | $Tags = `array()`
| ) |  |

Additing data to cache.

Parameters

  $SectionOriginName | - Name of the searching section (before transformation).
  $Data | - Data to cache.
  $Tags | - Data tags.

Note
  if the data already exists, then it will be deleted.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 475 of file cache.php.

{
try
{
$this->delete_data( $SectionOriginName );
$md5SectionOriginName = md5( $SectionOriginName );
$SectionSize = 32 + 1 + 32 + 1 + strlen( $Data );
$this->TableOfContents[ $md5SectionOriginName ] = array(
'section_size' => $SectionSize , 'read_cursor' => strlen( $this->Cache )
);
$this->Cache .= $md5SectionOriginName.":".sprintf( "%032d" , $SectionSize ).":$Data";
$this->TableOfContents[ $md5SectionOriginName ][ 'tags' ] = array_merge(
$Tags , array( '_cache_sys' , '_timeout' => time() )
);
if( $this->CacheSwitch === true )
{
$this->CacheWasUpdated = true;
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

data_exists | ( |  | $SectionOriginName | ) |

Check, wether data exists in the cache.

Parameters

  $SectionOriginName | - Name of the searching section (before transformation).

Exceptions

  Exception | An exception of this type is thrown.

Note
  Function validates data existance with checking timeout, so if data was timed out but presents in the cache, then function will return true.

Author
  Dodonov A.A.

Definition at line 560 of file cache.php.

{
try
{
if( $this->TableOfContents === false )
{
return( false );
}
else
{
return( isset( $this->TableOfContents[ md5( $SectionOriginName ) ] ) );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

delete_data | ( |  | $SectionOriginName | ) |

Deleting data from cache.

Parameters

  $SectionOriginName | - Name of the searching section (before transformation).

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 519 of file cache.php.

{
try
{
if( $this->CacheSwitch === false )
{
return;
}
$this->delete_section( md5( $SectionOriginName ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

delete_data_by_tag | ( |  | $Tag | ) |

Deleting data from cache by it's tag.

Parameters

  $Tag | - Tag of the deleting section.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 695 of file cache.php.

{
try
{
if( $this->CacheSwitch === false )
{
return;
}
$Sections = array();
foreach( $this->TableOfContents as $Key => $Value )
{
if( array_search( $Tag , $Value[ 'tags' ] ) !== false )
{
$Sections [] = $Key;
}
}
foreach( $Sections as $Key => $Value )
{
$this->delete_section( $Value );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

drop_cache | ( |  | ) |

Function drops cache.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 779 of file cache.php.

{
try
{
$PageName = $this->Security->get_gp( 'page_name' , 'command' , 'default' );
@unlink( dirname( __FILE__ ).'./data/'.$PageName.'.cache' );
@unlink( dirname( __FILE__ ).'./data/'.$PageName.'.table' );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

flush | ( |  | ) |

Function flushes all data on disk.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

save updated cache

save cache's table of content

Definition at line 738 of file cache.php.

{
try
{
if( $this->CacheWasUpdated && $this->CacheSwitch === true )
{
$this->drop_cache();
$PageName = $this->Security->get_gp( 'page_name' , 'command' , 'default' );
file_put_contents( dirname( __FILE__ ).'/data/'.$PageName.'.cache' , $this->Cache );
file_put_contents(
dirname( __FILE__ ).'/data/'.$PageName.'.table' , serialize( $this->TableOfContents )
);
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

get_data | ( |  | $SectionOriginName | ) |

Extracting cache data.

Parameters

  $SectionOriginName | - Name of the searching section (before transformation).

Returns
  false if no data was found or data

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 267 of file cache.php.

{
try
{
if( $this->TableOfContents === false )
{
return( false );
}
$md5SectionOriginName = md5( $SectionOriginName );
if( isset( $this->TableOfContents[ $md5SectionOriginName ] ) === false )
{
return( false );
}
$CreateDate = $this->TableOfContents[ $md5SectionOriginName ][ 'tags' ][ '_timeout' ];
if( time() - $CreateDate > $this->CacheTimeout )
{
$this->delete_data( $SectionOriginName );
return( false );
}
return( $this->fetch_data( $md5SectionOriginName ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

reset | ( |  | ) |

Function resets settings.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 152 of file cache.php.

{
try
{
$Conf = file_get_contents( dirname( __FILE__ ).'/conf/cf_cache' );
$Conf = explode( ';' , $Conf );
$Conf[ 0 ] = explode( '=' , $Conf[ 0 ] );
$Conf[ 1 ] = explode( '=' , $Conf[ 1 ] );
$this->CacheSwitch = $Conf[ 0 ][ 1 ] == 'on';
$this->CacheTimeout = intval( $Conf[ 1 ][ 1 ] );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

set_data | ( |  | $SectionOriginName,
|  |  | $Data
| ) |  |

Function sets data.

Parameters

  $SectionOriginName | - Name of the searching section (before transformation).
  $Data | - Data.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Додонов А.А.

Definition at line 414 of file cache.php.

{
try
{
if( $this->TableOfContents === false )
{
throw( new Exception( 'Cache is empty' ) );
}
$md5SectionOriginName = md5( $SectionOriginName );
if( isset( $this->TableOfContents[ $md5SectionOriginName ] ) )
{
$this->update_cache( $md5SectionOriginName , $Data );
$this->update_table( $md5SectionOriginName , $Data );
if( $this->CacheSwitch === true )
{
$this->CacheWasUpdated = true;
}
}
else
{
throw( new Exception( 'Section '.$SectionOriginName.' was not found' ) );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

## Field Documentation

$Cache

Cache.

Author
  Dodonov A.A.

Definition at line 38 of file cache.php.

$CacheSwitch = true

Enables or disables caching.

Author
  Dodonov A.A.

Definition at line 86 of file cache.php.

$CacheTimeout = 120

Cache's timeout. Default value is 120 seconds.

Author
  Dodonov A.A.

Definition at line 98 of file cache.php.

$CacheWasUpdated = false

Evidence of the updated cache.

Author
  Dodonov A.A.

Definition at line 62 of file cache.php.

$Security = false

Cached objects.

Author
  Dodonov A.A.

Definition at line 50 of file cache.php.

$TableOfContents = false

Cache description.

Author
  Dodonov A.A.

Definition at line 74 of file cache.php.

The documentation for this class was generated from the following file:

- packages/cache/cache.php