Overview

Namespaces

  • None
  • Wei
    • Validator

Classes

  • Apc
  • App
  • ArrayCache
  • Asset
  • Base
  • BaseCache
  • BaseController
  • Bicache
  • Cache
  • Config
  • Cookie
  • Couchbase
  • Counter
  • Db
  • DbCache
  • E
  • Env
  • Error
  • FileCache
  • Gravatar
  • Http
  • Lock
  • Logger
  • Memcache
  • Memcached
  • MongoCache
  • Password
  • PhpError
  • PhpFileCache
  • Pinyin
  • Record
  • Redis
  • Request
  • Response
  • Router
  • SafeUrl
  • Session
  • Soap
  • T
  • Ua
  • Upload
  • Url
  • Uuid
  • Validate
  • View
  • WeChatApp
  • Wei
  • Overview
  • Namespace
  • Class

Class FileCache

A cache service that stored data in files

Wei\Base
Extended by Wei\BaseCache
Extended by Wei\FileCache

Direct known subclasses

Wei\PhpFileCache
Namespace: Wei
Author: Twin Huang twinhuang@qq.com
Located at FileCache.php
Methods summary
public
# __construct( array $options = array() )

Constructor

Constructor

Parameters

$options

Throws

InvalidArgumentException
When option "wei" is not an instance of "Wei\Wei"

Overrides

Wei\Base::__construct()
public mixed
# get( string $key, integer $expire = null, callable $fn = null )

Retrieve an item

Retrieve an item

Parameters

$key
The name of item
$expire
The expire seconds of callback return value
$fn
The callback to execute when cache not found

Returns

mixed

Throws

RuntimeException
When set cache return false
public boolean
# set( string $key, mixed $value, integer $expire = 0 )

Store an item

Store an item

Parameters

$key
The name of item
$value
The value of item
$expire
The expire seconds, defaults to 0, means never expired

Returns

boolean
public boolean
# remove( string $key )

Remove an item

Remove an item

Parameters

$key
The name of item

Returns

boolean
public boolean
# exists( string $key )

Check if an item is exists

Check if an item is exists

Parameters

$key

Returns

boolean
public boolean
# add( string $key, mixed $value, integer $expire = 0 )

Add an item

Add an item

Parameters

$key
The name of item
$value
The value of item
$expire
The expire seconds, defaults to 0, means never expired

Returns

boolean
public boolean
# replace( string $key, mixed $value, integer $expire = 0 )

Replace an existing item

Replace an existing item

Parameters

$key
The name of item
$value
The value of item
$expire
The expire seconds, defaults to 0, means never expired

Returns

boolean
public integer|false
# incr( string $key, integer $offset = 1 )

Increment an item

Increment an item

Parameters

$key
The name of item
$offset
The value to increased

Returns

integer|false
Returns the new value on success, or false on failure
public boolean
# clear( )

Clear all items

Clear all items

Returns

boolean
public string
# getFile( string $key )

Get cache file by key

Get cache file by key

Parameters

$key

Returns

string
public
# setDir( string $dir )

Set the cache directory

Set the cache directory

Parameters

$dir

Returns


$this

Throws

RuntimeException
When failed to create the cache directory
public string
# getDir( )

Returns the cache directory

Returns the cache directory

Returns

string
protected resource|false
# openAndLock( string $file, string $mode, integer $operation )

Open and lock file

Open and lock file

Parameters

$file
file path
$mode
open mode
$operation
lock operation

Returns

resource|false
file handle or false
protected false|array
# readAndVerify( resource $handle, string $file )

Read file by handle and verify if content is expired

Read file by handle and verify if content is expired

Parameters

$handle
file handle
$file
file path

Returns

false|array
false or file content array
protected array
# getContent( string $file )

Receive file content by file name

Receive file content by file name

Parameters

$file

Returns

array
protected string
# prepareContent( string $content, integer $expire )

Prepare content for writing

Prepare content for writing

Parameters

$content
the value of cache
$expire
expire time

Returns

string
file content
protected boolean
# writeAndRelease( resource $handle, string $content, boolean $rewrite = false )

Write content, release lock and close file

Write content, release lock and close file

Parameters

$handle
file handle
$content
the value of cache
$rewrite
whether rewrite the whole file

Returns

boolean
Methods inherited from Wei\BaseCache
__invoke(), decr(), getFileContent(), getMulti(), getNamespace(), processGetResult(), setMulti(), setNamespace()
Methods inherited from Wei\Base
__call(), __get(), getOption(), setOption()
Properties summary
protected string $dir

The cache directory

The cache directory

# 'cache'
protected array $illegalChars

Illegal chars as the name of cache, would be replaced to "_"

Illegal chars as the name of cache, would be replaced to "_"

# array( '\\', '/', ':', '*', '?', '"', '<', '>', '|', "\r", "\n" )
protected string $ext

The cache file extension

The cache file extension

# 'cache'
Properties inherited from Wei\BaseCache
$namespace
Properties inherited from Wei\Base
$providers, $wei
Wei Framework API documentation generated by ApiGen