\seekquarry\yioop\libraryFileCache

Library of functions used to implement a simple file cache

Summary

Methods
Properties
Constants
__construct()
fileGetContents()
filePutContents()
get()
set()
checksum()
clear()
$cache_file
$dir_name
NUMBER_OF_BINS
MAX_FILES_IN_A_BIN
updateCache()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Constants

NUMBER_OF_BINS

NUMBER_OF_BINS

Total number of bins to cycle between

MAX_FILES_IN_A_BIN

MAX_FILES_IN_A_BIN

Maximum number of files in a bin

Properties

$cache_file

$cache_file : string

File used to serve last cache request

Type

string

$dir_name

$dir_name : string

Folder name to use for this FileCache

Type

string

Methods

__construct()

__construct(string  $dir_name,   $web_site = null) 

Creates the directory for the file cache, sets how frequently all items in the cache expire

Parameters

string $dir_name

folder name of where to put the file cache

$web_site

fileGetContents()

fileGetContents(string  $filename, boolean  $force_read = false) : string

Either a wrapper for file_get_contents, or if a WebSite object is being used to serve pages, it reads it in using blocking I/O file_get_contents() and caches it before return its string contents.

Note this function assumes that only the web server is performing I/O with this file. filemtime() can be used to see if a file on disk has been changed and then you can use $force_read = true below to force re- reading the file into the cache

Parameters

string $filename

name of file to get contents of

boolean $force_read

whether to force the file to be read from presistent storage rather than the cache

Returns

string —

contents of the file given by $filename

filePutContents()

filePutContents(string  $filename, string  $data) 

Either a wrapper for file_put_contents, or if a WebSite object is being used to serve pages, writes $data to the persistent file with name $filename. Saves a copy in the RAM cache if there is a copy already there.

Parameters

string $filename

name of file to write to persistent storages

string $data

string of data to store in file

get()

get(string  $key) : mixed

Retrieve data associated with a key that has been put in the cache

Parameters

string $key

the key to look up

Returns

mixed —

the data associated with the key if it exists, false otherwise

set()

set(string  $key, mixed  $value) 

Stores in the file cache a key-value pair

Parameters

string $key

to associate with value

mixed $value

to store

checksum()

checksum(string  $key) : integer

Makes a 0 - self::NUMBER_OF_BINS value out of the provided key

Parameters

string $key

to convert to a random value between 0 - self::NUMBER_OF_BINS

Returns

integer —

value between 0 and self::NUMBER_OF_BINS

clear()

clear() 

Deletes cache key value files and ram copies of key values stored in the this file cache

updateCache()

updateCache(string  $key) 

Used to mark a cache item, and keep track of rounds according to the marker algorith. This function determine if the cache is too full and if so eject an item.

Parameters

string $key

that was just read from or written to. Might need to be marked according to Marker algorithm