1 /*
2  * lftp - file transfer program
3  *
4  * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net)
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <config.h>
21 #include "Cache.h"
22 
Trim()23 void Cache::Trim()
24 {
25    long sizelimit=res_max_size->Query(0);
26 
27    long size=0;
28    CacheEntry **scan=&chain;
29    while(scan[0])
30    {
31       if(scan[0]->Stopped())
32 	 delete replace_value(scan[0],scan[0]->next);
33       else
34       {
35 	 size+=scan[0]->EstimateSize();
36 	 scan=&scan[0]->next;
37       }
38    }
39 // printf("Cache::Trim size=%ld, limit=%ld\n",size,sizelimit);
40    while(chain && size>sizelimit)
41    {
42       size-=chain->EstimateSize();
43       delete replace_value(chain,chain->next);
44    }
45 }
Flush()46 void Cache::Flush()
47 {
48    while(chain)
49       delete replace_value(chain,chain->next);
50 }
IterateFirst()51 CacheEntry *Cache::IterateFirst()
52 {
53    curr=&chain;
54    return *curr;
55 }
IterateNext()56 CacheEntry *Cache::IterateNext()
57 {
58    curr=&curr[0]->next;
59    return *curr;
60 }
IterateDelete()61 CacheEntry *Cache::IterateDelete()
62 {
63    delete replace_value(curr[0],curr[0]->next);
64    return *curr;
65 }
66