char *path;
const char *dir;
+ if (!key || !*key || *key != '/')
+ return NULL;
+
dir = get_cache_dir();
if (!dir)
return NULL;
- path = malloc(strlen(dir) + 1 + strlen(key) + strlen("/data.json") + 1);
- sprintf(path, "%s%s/data.json", dir, key);
+ path = malloc(strlen(dir) + 1 + strlen(key) + strlen("/data") + 1);
+ sprintf(path, "%s%s.data", dir, key);
return path;
}
char *path, *content;
path = key_to_path(key);
- if (!path)
+ if (!path) {
+ log_err(_("file cache, invalid key: %s"), key);
return NULL;
+ }
content = file_get_content(path);
-
+
if (content)
log_debug(_("file cache hit %s"), key);
else
log_debug(_("file cache miss %s %s"), key, path);
-
+
free(path);
-
+
return content;
}
-
-void fcache_put(const char *key, char *value)
+
+void fcache_put(const char *key, const char *value)
{
char *path, *dir, *tmp;
FILE *f;