This repository has been archived by the owner on Sep 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.h
99 lines (79 loc) · 2.47 KB
/
cache.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef CLIB_CACHE_H
#define CLIB_CACHE_H
#include <stdbool.h>
#include <stdint.h>
#include <time.h>
/**
* Internal setup, creates the base cache dir if necessary
*
* @param expiration Cache expiration in seconds
*
* @return 0 on success, -1 otherwise
*/
int clib_cache_init(time_t expiration);
/**
* @return The base base dir
*/
const char *clib_cache_dir(void);
/**
* At this point the package object is not built yet, and can't rely on it
*
* @return 0/1 if the package.json is cached
*/
int clib_cache_has_json(char *author, char *name, char *version);
/**
* @return The content of the cached package.json, or NULL on error, if not found, or expired
*/
char *clib_cache_read_json(char *author, char *name, char *version);
/**
* @return Number of written bytes, or -1 on error
*/
int clib_cache_save_json(char *author, char *name, char *version, char *content);
/**
* @return Number of written bytes, or -1 on error
*/
int clib_cache_delete_json(char *author, char *name, char *version);
/**
* @return 0/1 if the search cache exists
*/
int clib_cache_has_search(void);
/**
* @return The content of the search cache, NULL on error, if not found, or expired
*/
char *clib_cache_read_search(void);
/**
* @return Number of written bytes, or -1 on error, or if there is no search cahce
*/
int clib_cache_save_search(char *content);
/**
* @return 0 on success, -1 otherwise
*/
int clib_cache_delete_search(void);
/**
* @return 0/1 if the packe is cached
*/
int clib_cache_has_package(char *author, char *name, char *version);
/**
* @return 0/1 if the cached package modified date is more or less then the given expiration.
* -1 if the package is not cached
*/
int clib_cache_is_expired_package(char *author, char *name, char *version);
/**
* @param target_dir Where the cached package should be copied
*
* @return 0 on success, -1 on error, if the package is not found in the cache.
* If the cached package is expired, it will be deleted, and -2 returned
*/
int clib_cache_load_package(char *author, char *name, char *version, char *target_dir);
/**
* @param pkg_dir The downloaded package (e.g. ./deps/my_package).
* If the package was already cached, it will be deleted first, then saved
*
* @return 0 on success, -1 on error
*/
int clib_cache_save_package(char *author, char *name, char *version, char *pkg_dir);
/**
* @return 0 on success, -1 on error
*/
int clib_cache_delete_package(char *author, char *name, char *version);
#endif