Merge lp:~dobey/unity-scope-click/add-cache into lp:unity-scope-click

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: 59
Merged at revision: 57
Proposed branch: lp:~dobey/unity-scope-click/add-cache
Merge into: lp:unity-scope-click
Diff against target: 48 lines (+22/-0)
1 file modified
src/click-webservice.vala (+22/-0)
To merge this branch: bzr merge lp:~dobey/unity-scope-click/add-cache
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Alejandro J. Cura (community) Approve
Review via email: mp+188069@code.launchpad.net

Commit message

Add support for caching of the REST responses to the scope.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Branch looks good. 128mb cache for this sounds huge, I think 8 or 16mb should be plenty.

review: Approve
59. By dobey

Make the cache size 16 MiB max.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/click-webservice.vala'
2--- src/click-webservice.vala 2013-09-23 23:00:12 +0000
3+++ src/click-webservice.vala 2013-09-27 19:27:48 +0000
4@@ -32,6 +32,12 @@
5 const string JSON_FIELD_DESCRIPTION = "description";
6 const string JSON_FIELD_KEYWORDS = "keywords";
7
8+// The size of the cache for click app data
9+// == SIZE_IN_MB * 1024 * 1024
10+const uint CACHE_SIZE_MB = 16;
11+const uint CACHE_SIZE_BYTES = CACHE_SIZE_MB * 1024 * 1024;
12+
13+
14 errordomain WebserviceError {
15 HTTP_ERROR,
16 JSON_ERROR
17@@ -195,15 +201,31 @@
18
19 class WebClient : GLib.Object {
20 static Soup.SessionAsync http_session = null;
21+ static Soup.Cache cache = null;
22 private const string USER_AGENT = "UnityScopeClick/0.1 (libsoup)";
23
24 public static Soup.SessionAsync get_webclient () {
25 if (http_session == null) {
26 http_session = new Soup.SessionAsync ();
27 http_session.user_agent = USER_AGENT;
28+
29+ var cache_obj = get_cache ();
30+ http_session.add_feature (cache_obj);
31 }
32 return http_session;
33 }
34+
35+ public static Soup.Cache get_cache () {
36+ if (cache == null) {
37+ string cache_dir = GLib.Path.build_path (GLib.Path.DIR_SEPARATOR_S,
38+ GLib.Environment.get_user_cache_dir (),
39+ "com.ubuntu.unity-scope-click");
40+ cache = new Soup.Cache(cache_dir, Soup.CacheType.SINGLE_USER);
41+ cache.set_max_size (CACHE_SIZE_BYTES);
42+ cache.load ();
43+ }
44+ return cache;
45+ }
46 }
47
48 class ClickWebservice : GLib.Object

Subscribers

People subscribed via source and target branches

to all changes: