/* */ #ifndef D_WR_DISK_CACHE_H #define D_WR_DISK_CACHE_H #include "common.h" #include #include "a2functional.h" namespace aria2 { class WrDiskCacheEntry; class WrDiskCache { public: WrDiskCache(size_t limit); ~WrDiskCache(); // Adds the cache entry |ent| to the storage. The size of cached // data of ent is added to total_. bool add(WrDiskCacheEntry* ent); // Removes the cache entry |ent| from the storage. The size of // cached data of ent is subtracted from total_. bool remove(WrDiskCacheEntry* ent); // Updates the already added entry |ent|. The |delta| means how many // bytes is increased in this update. If the size is reduced, use // negative value. bool update(WrDiskCacheEntry* ent, ssize_t delta); // Evicts entries from storage so that total size of cache is kept // under the limit. void ensureLimit(); size_t getSize() const { return total_; } private: typedef std::set> EntrySet; // Maximum number of bytes the storage can cache. size_t limit_; // Current number of bytes cached. size_t total_; EntrySet set_; int64_t clock_; }; } // namespace aria2 #endif // D_WR_DISK_CACHE_H