aboutsummaryrefslogtreecommitdiff
path: root/oop2eindopdr/CacheManager.h
blob: e441b1ba180dd7a3892ad354ef447f313bb923d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include <string>
#include <vector>

/** @brief cache storage manager */
class CacheManager {
private:
	/** @brief currently opened cache location */
	std::string cache_path;
	/** @brief pointers to open file handles */
	std::vector<std::fstream*> files;
	/** @brief add cache path before filename */
	virtual std::string prefix_cache_path(const char* filename);
public:
	/** @brief initialize CacheManager class at `cache_path` */
	CacheManager(const char* cache_path);
	CacheManager(std::string cache_path);
	/** @brief close cache */
	virtual ~CacheManager();
	/** @brief create cache folder structure */
	virtual void init_cache();
	/** @brief update cache date */
	virtual void update_cache();
	/**
	 * @brief check cache file structure
	 *
	 * automatically creates cache when non-existant
	 */
	virtual void verify_cache();

	/** @brief get fstream for file in cache or create file */
	virtual std::fstream* cache_get(const char* filename);
	virtual std::fstream* cache_get(std::string filename);
	/** @brief check if file exists in cache */
	virtual bool cache_exists(const char* filename);
	virtual bool cache_exists(std::string filename);

	/** @brief currently opened cache update unix timestamp */
	uint64_t age;
};