#pragma once #include "../Interface/Database.h" #include "../Interface/Types.h" #include "../Interface/Mutex.h" #include "../Interface/Condition.h" #include "../Interface/Thread.h" #include class FileCache : public IThread { public: typedef db_results(*get_data_callback_t)(size_t, void *userdata); struct SCacheValue { SCacheValue(std::string fullpath, std::string hashpath) : exists(true), fullpath(fullpath), hashpath(hashpath) { } SCacheValue(void) : exists(false) { } bool exists; std::string fullpath; std::string hashpath; }; struct SCacheKey { SCacheKey(const char thash[64], int64 filesize) : filesize(filesize) { memcpy(hash, thash, 64); } SCacheKey(void) : filesize(-1) { memset(hash, 0, 64); } void operator=(const SCacheKey& other) { memcpy(hash, other.hash, 64); filesize=other.filesize; } bool operator==(const SCacheKey& other) const { return memcmp(hash, other.hash, 64)==0 && filesize==other.filesize; } bool operator!=(const SCacheKey& other) const { return !(*this==other); } bool operator<(const SCacheKey& other) const { int mres=memcmp(hash, other.hash, 64); return mres<0 || (mres==0 && filesize cache_buffer; static std::map del_buffer; static IMutex *mutex; static ICondition *cond; };