1 module soup.Cache;
2 
3 private import glib.ConstructionException;
4 private import glib.Str;
5 private import gobject.ObjectG;
6 private import soup.SessionFeatureIF;
7 private import soup.SessionFeatureT;
8 private import soup.c.functions;
9 public  import soup.c.types;
10 
11 
12 /**
13  * #SoupCache implements a file-based cache for HTTP resources.
14  */
15 public class Cache : ObjectG, SessionFeatureIF
16 {
17 	/** the main Gtk struct */
18 	protected SoupCache* soupCache;
19 
20 	/** Get the main Gtk struct */
21 	public SoupCache* getCacheStruct(bool transferOwnership = false)
22 	{
23 		if (transferOwnership)
24 			ownedRef = false;
25 		return soupCache;
26 	}
27 
28 	/** the main Gtk struct as a void* */
29 	protected override void* getStruct()
30 	{
31 		return cast(void*)soupCache;
32 	}
33 
34 	/**
35 	 * Sets our main struct and passes it to the parent class.
36 	 */
37 	public this (SoupCache* soupCache, bool ownedRef = false)
38 	{
39 		this.soupCache = soupCache;
40 		super(cast(GObject*)soupCache, ownedRef);
41 	}
42 
43 	// add the SessionFeature capabilities
44 	mixin SessionFeatureT!(SoupCache);
45 
46 
47 	/** */
48 	public static GType getType()
49 	{
50 		return soup_cache_get_type();
51 	}
52 
53 	/**
54 	 * Creates a new #SoupCache.
55 	 *
56 	 * Params:
57 	 *     cacheDir = the directory to store the cached data, or %NULL
58 	 *         to use the default one. Note that since the cache isn't safe to access for
59 	 *         multiple processes at once, and the default directory isn't namespaced by
60 	 *         process, clients are strongly discouraged from passing %NULL.
61 	 *     cacheType = the #SoupCacheType of the cache
62 	 *
63 	 * Returns: a new #SoupCache
64 	 *
65 	 * Since: 2.34
66 	 *
67 	 * Throws: ConstructionException GTK+ fails to create the object.
68 	 */
69 	public this(string cacheDir, SoupCacheType cacheType)
70 	{
71 		auto __p = soup_cache_new(Str.toStringz(cacheDir), cacheType);
72 
73 		if(__p is null)
74 		{
75 			throw new ConstructionException("null returned by new");
76 		}
77 
78 		this(cast(SoupCache*) __p, true);
79 	}
80 
81 	/**
82 	 * Will remove all entries in the @cache plus all the cache files.
83 	 *
84 	 * Since: 2.34
85 	 */
86 	public void clear()
87 	{
88 		soup_cache_clear(soupCache);
89 	}
90 
91 	/**
92 	 * Synchronously writes the cache index out to disk. Contrast with
93 	 * soup_cache_flush(), which writes pending cache
94 	 * <emphasis>entries</emphasis> to disk.
95 	 *
96 	 * You must call this before exiting if you want your cache data to
97 	 * persist between sessions.
98 	 *
99 	 * Since: 2.34.
100 	 */
101 	public void dump()
102 	{
103 		soup_cache_dump(soupCache);
104 	}
105 
106 	/**
107 	 * This function will force all pending writes in the @cache to be
108 	 * committed to disk. For doing so it will iterate the #GMainContext
109 	 * associated with @cache's session as long as needed.
110 	 *
111 	 * Contrast with soup_cache_dump(), which writes out the cache index
112 	 * file.
113 	 *
114 	 * Since: 2.34
115 	 */
116 	public void flush()
117 	{
118 		soup_cache_flush(soupCache);
119 	}
120 
121 	/**
122 	 * Gets the maximum size of the cache.
123 	 *
124 	 * Returns: the maximum size of the cache, in bytes.
125 	 *
126 	 * Since: 2.34
127 	 */
128 	public uint getMaxSize()
129 	{
130 		return soup_cache_get_max_size(soupCache);
131 	}
132 
133 	/**
134 	 * Loads the contents of @cache's index into memory.
135 	 *
136 	 * Since: 2.34
137 	 */
138 	public void load()
139 	{
140 		soup_cache_load(soupCache);
141 	}
142 
143 	/**
144 	 * Sets the maximum size of the cache.
145 	 *
146 	 * Params:
147 	 *     maxSize = the maximum size of the cache, in bytes
148 	 *
149 	 * Since: 2.34
150 	 */
151 	public void setMaxSize(uint maxSize)
152 	{
153 		soup_cache_set_max_size(soupCache, maxSize);
154 	}
155 }