Hashfile class

The class is designed for working with hashes kept on disk. Unlike hash class, objects of this class are considered to be always defined (def) and have no numeric value.

hash class keeps its values in memory, hashfile keeps them on disk and it is possible to separately specify time to keep each key-value pair.
Note: currently to keep one
hashfile two files are used: .dir and .pag.
Note: there is a limit on key and value strings, together they must not exceed
8000 bytes.

Reading and writing of data performed very quickly-Parser works only with necessary data files fragments.
On simple tasks
hashfile performs considerably faster then databases.
Note: file can be changed only by one script at a time, others are waiting for it to complete processing of request.

Say, it's desirable to get some information from visitor on one page of site and to be able to show it on other page. And it is necessary to prevent visitor from seeing or faking it in the middle.

It is possible to store information to
hashfile, associated with some random string-session identifier. That identifier can be stored to cookie, data are now kept on server, are not reachable and cannot be faked by visitor.

# opening/creating file with information
after that

arbitrary value]
# …storing arbitrary $information_string under sid 
key for 2 days
$.value[$information_string] $.expires(2)]

# …
like this can read the value stored earlier
if since the moment we stored it passed less then 2 days

Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 24.12.2004