1 /* bzflag
2  * Copyright (c) 1993-2021 Tim Riker
3  *
4  * This package is free software;  you can redistribute it and/or
5  * modify it under the terms of the license found in the file
6  * named COPYING that should have accompanied this file.
7  *
8  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 #ifndef CACHE_MANAGER_H
14 #define CACHE_MANAGER_H
15 
16 #include <time.h>
17 #include <string>
18 #include <vector>
19 
20 class CacheManager
21 {
22 public:
23     CacheManager();
24     ~CacheManager();
25 
26     typedef struct
27     {
28         std::string url;
29         time_t usedDate;
30         std::string name;
31         int size;
32         time_t date;
33         std::string key;
34     } CacheRecord;
35 
36     bool isCacheFileType(const std::string &name) const;
37     std::string getLocalName(const std::string &name) const;
38 
39     bool loadIndex();
40     bool saveIndex();
41 
42     bool findURL(const std::string& url, CacheRecord& record);
43     bool addFile(CacheRecord& rec, const void* data);
44 
45     std::vector<CacheRecord> getCacheList() const;
46 
47     void limitCacheSize();
48 
49 private:
50     int findRecord(const std::string& url);
51 
52 private:
53     std::string indexName;
54     std::string getIndexPath();
55     std::vector<CacheRecord> records;
56 };
57 
58 extern CacheManager CACHEMGR;
59 
60 #endif
61 
62 /*
63  * Local Variables: ***
64  * mode: C ***
65  * tab-width: 8 ***
66  * c-basic-offset: 2 ***
67  * indent-tabs-mode: t ***
68  * End: ***
69  * ex: shiftwidth=2 tabstop=8
70  */
71