2 * Copyright (C) 2010-2013 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <sys/types.h>
31 #include "ttrss_cache.h"
33 static char *cache_dir;
35 static const char *get_cache_dir()
40 home = getenv("HOME");
45 cache_dir = path_append(home, ".prss/cache");
46 mkdirs(cache_dir, 0777);
52 static gchar *content_get_path(const struct headline *h)
54 const char *cache_dir;
56 cache_dir = get_cache_dir();
58 return g_strdup_printf("%s/%d", cache_dir, h->id);
63 static void file_set_content(const char *path, const char *content)
67 log_debug("file_set_content(): path=%s", path);
69 fp = fopen(path, "w");
71 fwrite(content, 1, strlen(content), fp);
76 void cache_put(const struct headline *h, const char *content)
80 path = content_get_path(h);
83 file_set_content(path, content);
88 int cache_exists(const struct headline *h)
94 path = content_get_path(h);
96 if (stat(path, &s) == -1)
106 char *cache_get(const struct headline *h)
108 char *content, *path;
110 path = content_get_path(h);
112 content = file_get_content(path);