This class caches files for the HTTP server. More...
#include <DcFileCacher.h>
Classes | |
class | CdcFile |
This is an inner class that represents a file to store. | |
Public Member Functions | |
CdcFileCacher () | |
Constructor - Don't do much. | |
virtual | ~CdcFileCacher () |
Destructor - Delete the map and all its content, and delete the limiter thread. | |
void | Init () |
Since this class will form just one static object, I will use Init to initialize the object, instead of the constructor (that runs before main) Init finds out how many files to cache, and if this is a positive number, it starts the limiter thread. | |
bool | GetFile (const CdcString &name, const CdcHttpTime &time, CdcBuffer &data) |
Try to get a file from the cache, by name and date of last modification. | |
bool | PutFile (const CdcString &name, const CdcHttpTime &time, const CdcBuffer &data) |
Try to put a file into the cache, by name and date of last modification. | |
void | DeleteLast () |
This function runs on the map, finds the last accessed file and deletes it. | |
Friends | |
int | DcLimit (void *pParam) |
Global function to the number of files limiter thread. |
This class caches files for the HTTP server.
it stores the file name, data and last modified time in a map. The class is thread safe, it built to be accessed from multiple threads.
In addition there is a lower priority thread that deletes the last access cached file, if there are too many files in the cache. In the server configuration file Cache-Limit is the maximum number of files to cache. If this number is set to 0 (or missing) this class will not do a thing (cache or start the cleanup thread).
What make the File cacher efficient is the Copy On Write (or Reference Counting) of the CdcBuffer class. So its not really copies the data each time we transfer a buffer from object to object.
Definition at line 53 of file DcFileCacher.h.
CdcFileCacher::CdcFileCacher | ( | ) |
Constructor - Don't do much.
DcFilecacher.cpp: implementation of the CdcFilecacher class.
The work get done in Init.
for documentation see the header file.
Definition at line 29 of file DcFileCacher.cpp.
CdcFileCacher::~CdcFileCacher | ( | ) | [virtual] |
Destructor - Delete the map and all its content, and delete the limiter thread.
Definition at line 33 of file DcFileCacher.cpp.
void CdcFileCacher::DeleteLast | ( | ) |
This function runs on the map, finds the last accessed file and deletes it.
if the file has been accessed since it was found, the function will return without doing a thing.
Definition at line 116 of file DcFileCacher.cpp.
bool CdcFileCacher::GetFile | ( | const CdcString & | name, |
const CdcHttpTime & | time, | ||
CdcBuffer & | data | ||
) |
Try to get a file from the cache, by name and date of last modification.
name | The name of the required file. |
time | The last modified time of the required file. |
data | Reference to the data of the file that will be returned from the cache (if the file does not exist in the cache, this parameter will not be changed). |
Definition at line 58 of file DcFileCacher.cpp.
void CdcFileCacher::Init | ( | ) |
Since this class will form just one static object, I will use Init to initialize the object, instead of the constructor (that runs before main) Init finds out how many files to cache, and if this is a positive number, it starts the limiter thread.
Definition at line 44 of file DcFileCacher.cpp.
bool CdcFileCacher::PutFile | ( | const CdcString & | name, |
const CdcHttpTime & | time, | ||
const CdcBuffer & | data | ||
) |
Try to put a file into the cache, by name and date of last modification.
name | The name of the file to insert. |
time | The last modified time of the file to insert. |
data | Reference to the data of the file. |
Definition at line 81 of file DcFileCacher.cpp.
int DcLimit | ( | void * | pParam ) | [friend] |
Global function to the number of files limiter thread.
Definition at line 147 of file DcFileCacher.cpp.