|
Packit Service |
a2489d |
/*
|
|
Packit Service |
a2489d |
* lftp - file transfer program
|
|
Packit Service |
a2489d |
*
|
|
Packit Service |
a2489d |
* Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net)
|
|
Packit Service |
a2489d |
*
|
|
Packit Service |
a2489d |
* This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
a2489d |
* it under the terms of the GNU General Public License as published by
|
|
Packit Service |
a2489d |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
a2489d |
* (at your option) any later version.
|
|
Packit Service |
a2489d |
*
|
|
Packit Service |
a2489d |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
a2489d |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a2489d |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
a2489d |
* GNU General Public License for more details.
|
|
Packit Service |
a2489d |
*
|
|
Packit Service |
a2489d |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
a2489d |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
a2489d |
*/
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
#ifndef CACHE_H
|
|
Packit Service |
a2489d |
#define CACHE_H
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
#include "Timer.h"
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
class CacheEntry : public Timer
|
|
Packit Service |
a2489d |
{
|
|
Packit Service |
a2489d |
friend class Cache;
|
|
Packit Service |
a2489d |
CacheEntry *next;
|
|
Packit Service |
a2489d |
public:
|
|
Packit Service |
a2489d |
CacheEntry() { next=0; }
|
|
Packit Service |
a2489d |
virtual int EstimateSize() const { return 1; }
|
|
Packit Service |
a2489d |
virtual ~CacheEntry() {}
|
|
Packit Service |
a2489d |
};
|
|
Packit Service |
a2489d |
class Cache
|
|
Packit Service |
a2489d |
{
|
|
Packit Service |
a2489d |
const ResType *res_max_size;
|
|
Packit Service |
a2489d |
const ResType *res_enable;
|
|
Packit Service |
a2489d |
protected:
|
|
Packit Service |
a2489d |
CacheEntry *chain;
|
|
Packit Service |
a2489d |
CacheEntry **curr;
|
|
Packit Service |
a2489d |
CacheEntry *IterateFirst();
|
|
Packit Service |
a2489d |
CacheEntry *IterateNext();
|
|
Packit Service |
a2489d |
CacheEntry *IterateDelete();
|
|
Packit Service |
a2489d |
public:
|
|
Packit Service |
a2489d |
void Trim();
|
|
Packit Service |
a2489d |
void Flush();
|
|
Packit Service |
a2489d |
Cache(const ResType *s,const ResType *e) {
|
|
Packit Service |
a2489d |
res_max_size=s;
|
|
Packit Service |
a2489d |
res_enable=e;
|
|
Packit Service |
a2489d |
chain=0;
|
|
Packit Service |
a2489d |
curr=0;
|
|
Packit Service |
a2489d |
}
|
|
Packit Service |
a2489d |
~Cache() { Flush(); }
|
|
Packit Service |
a2489d |
bool IsEnabled(const char *closure) { return res_enable->QueryBool(closure); }
|
|
Packit Service |
a2489d |
long SizeLimit() { return res_max_size->Query(0); }
|
|
Packit Service |
a2489d |
void AddCacheEntry(CacheEntry *e) {
|
|
Packit Service |
a2489d |
e->next=chain;
|
|
Packit Service |
a2489d |
chain=e;
|
|
Packit Service |
a2489d |
}
|
|
Packit Service |
a2489d |
};
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
#endif//CACHE_H
|