Merge lp:~jamesh/thumbnailer/landing-20150622 into lp:thumbnailer

Proposed by James Henstridge
Status: Merged
Approved by: Michi Henning
Approved revision: 131
Merged at revision: 122
Proposed branch: lp:~jamesh/thumbnailer/landing-20150622
Merge into: lp:thumbnailer
Diff against target: 30725 lines (+25175/-3830)
203 files modified
CMakeLists.txt (+105/-31)
COPYING.GPL (+674/-0)
CTestCustom.cmake.in (+17/-0)
HACKING (+121/-0)
cmake/coverage.cmake (+0/-34)
data/CMakeLists.txt (+0/-1)
data/com.canonical.Unity.Thumbnailer.gschema.xml (+67/-0)
debian/changelog (+49/-0)
debian/control (+13/-28)
debian/copyright (+22/-2)
debian/libthumbnailer-dev.install (+0/-3)
debian/libthumbnailer0.install (+0/-2)
debian/libthumbnailer0.symbols (+0/-7)
debian/rules (+3/-0)
debian/thumbnailer-service.install (+2/-0)
include/CMakeLists.txt (+0/-11)
include/core/cache_codec.h (+50/-0)
include/core/cache_discard_policy.h (+41/-0)
include/core/cache_events.h (+103/-0)
include/core/internal/cache_event_indexes.h (+46/-0)
include/core/internal/persistent_string_cache_impl.h (+191/-0)
include/core/internal/persistent_string_cache_stats.h (+237/-0)
include/core/optional.h (+35/-0)
include/core/persistent_cache.h (+3104/-0)
include/core/persistent_cache_stats.h (+230/-0)
include/core/persistent_string_cache.h (+730/-0)
include/internal/artdownloader.h (+44/-16)
include/internal/artreply.h (+60/-0)
include/internal/audioimageextractor.h (+0/-41)
include/internal/check_access.h (+42/-0)
include/internal/config.h.in (+4/-7)
include/internal/file_io.h (+51/-0)
include/internal/gobj_memory.h (+170/-65)
include/internal/httpdownloader.h (+25/-13)
include/internal/image.h (+82/-0)
include/internal/imageextractor.h (+59/-22)
include/internal/imagescaler.h (+0/-55)
include/internal/lastfmdownloader.h (+0/-45)
include/internal/make_directories.h (+44/-0)
include/internal/mediaartcache.h (+0/-61)
include/internal/raii.h (+55/-0)
include/internal/safe_strerror.h (+38/-0)
include/internal/settings.h (+72/-0)
include/internal/soupdownloader.h (+0/-40)
include/internal/thumbnailcache.h (+0/-50)
include/internal/thumbnailer.h (+128/-47)
include/internal/trace.h (+45/-0)
include/internal/ubuntuserverdownloader.h (+49/-21)
include/service/dbus_names.h (+40/-0)
include/thumbnailer.pc.in (+0/-10)
plugins/Ubuntu/Thumbnailer.0.1/CMakeLists.txt (+11/-2)
plugins/Ubuntu/Thumbnailer.0.1/albumartgenerator.cpp (+56/-52)
plugins/Ubuntu/Thumbnailer.0.1/albumartgenerator.h (+15/-8)
plugins/Ubuntu/Thumbnailer.0.1/artgeneratorcommon.cpp (+45/-19)
plugins/Ubuntu/Thumbnailer.0.1/artgeneratorcommon.h (+12/-6)
plugins/Ubuntu/Thumbnailer.0.1/artistartgenerator.cpp (+56/-52)
plugins/Ubuntu/Thumbnailer.0.1/artistartgenerator.h (+18/-11)
plugins/Ubuntu/Thumbnailer.0.1/plugin.cpp (+65/-24)
plugins/Ubuntu/Thumbnailer.0.1/plugin.h (+14/-7)
plugins/Ubuntu/Thumbnailer.0.1/thumbnailerimageresponse.cpp (+117/-0)
plugins/Ubuntu/Thumbnailer.0.1/thumbnailerimageresponse.h (+68/-0)
plugins/Ubuntu/Thumbnailer.0.1/thumbnailgenerator.cpp (+77/-77)
plugins/Ubuntu/Thumbnailer.0.1/thumbnailgenerator.h (+25/-16)
src/CMakeLists.txt (+43/-36)
src/artdownloader.cpp (+40/-0)
src/audioimageextractor.cpp (+0/-58)
src/check_access.cpp (+83/-0)
src/core/CMakeLists.txt (+13/-0)
src/core/internal/CMakeLists.txt (+5/-0)
src/core/internal/persistent_string_cache_impl.cpp (+1649/-0)
src/core/persistent_cache_stats.cpp (+219/-0)
src/core/persistent_string_cache.cpp (+239/-0)
src/file_io.cpp (+183/-0)
src/image.cpp (+484/-0)
src/imageextractor.cpp (+149/-89)
src/imagescaler.cpp (+0/-163)
src/lastfmdownloader.cpp (+0/-95)
src/libthumbnailer.map (+0/-15)
src/make_directories.cpp (+51/-0)
src/mediaartcache.cpp (+0/-225)
src/safe_strerror.cpp (+72/-0)
src/service/CMakeLists.txt (+20/-17)
src/service/admininterface.cpp (+141/-0)
src/service/admininterface.h (+65/-0)
src/service/admininterface.xml (+41/-0)
src/service/bus.xml (+9/-0)
src/service/com.canonical.Thumbnailer.service.in (+0/-1)
src/service/credentialscache.cpp (+187/-0)
src/service/credentialscache.h (+81/-0)
src/service/dbusinterface.cpp (+333/-237)
src/service/dbusinterface.h (+71/-27)
src/service/dbusinterface.xml (+14/-11)
src/service/handler.cpp (+454/-0)
src/service/handler.h (+91/-0)
src/service/inactivityhandler.cpp (+63/-0)
src/service/inactivityhandler.h (+49/-0)
src/service/main.cpp (+80/-43)
src/service/ratelimiter.cpp (+69/-0)
src/service/ratelimiter.h (+63/-0)
src/service/stats.cpp (+105/-0)
src/service/stats.h (+75/-0)
src/settings.cpp (+170/-0)
src/soupdownloader.cpp (+0/-46)
src/thumbnailcache.cpp (+0/-371)
src/thumbnailer-admin/CMakeLists.txt (+33/-0)
src/thumbnailer-admin/action.h (+66/-0)
src/thumbnailer-admin/clear.cpp (+115/-0)
src/thumbnailer-admin/clear.h (+50/-0)
src/thumbnailer-admin/dbus_connection.cpp (+58/-0)
src/thumbnailer-admin/dbus_connection.h (+57/-0)
src/thumbnailer-admin/get_local_thumbnail.cpp (+113/-0)
src/thumbnailer-admin/get_local_thumbnail.h (+52/-0)
src/thumbnailer-admin/get_remote_thumbnail.cpp (+129/-0)
src/thumbnailer-admin/get_remote_thumbnail.h (+53/-0)
src/thumbnailer-admin/parse_size.cpp (+62/-0)
src/thumbnailer-admin/parse_size.h (+39/-0)
src/thumbnailer-admin/show_stats.cpp (+223/-0)
src/thumbnailer-admin/show_stats.h (+55/-0)
src/thumbnailer-admin/shutdown.cpp (+74/-0)
src/thumbnailer-admin/shutdown.h (+47/-0)
src/thumbnailer-admin/thumbnailer-admin.cpp (+143/-0)
src/thumbnailer-admin/util.cpp (+79/-0)
src/thumbnailer-admin/util.h (+49/-0)
src/thumbnailer.cpp (+735/-303)
src/trace.cpp (+103/-0)
src/ubuntuserverdownloader.cpp (+302/-74)
src/vs-thumb/CMakeLists.txt (+13/-0)
src/vs-thumb/thumbnailextractor.cpp (+430/-0)
src/vs-thumb/thumbnailextractor.h (+56/-0)
src/vs-thumb/vs-thumb.cpp (+90/-207)
tests/CMakeLists.txt (+52/-30)
tests/basic.cpp (+0/-212)
tests/check_access/CMakeLists.txt (+4/-0)
tests/check_access/check_access_test.cpp (+64/-0)
tests/copyright/CMakeLists.txt (+6/-0)
tests/copyright/check_copyright.sh (+53/-0)
tests/core/CMakeLists.txt (+8/-0)
tests/core/internal/CMakeLists.txt (+1/-0)
tests/core/internal/persistent_string_cache_impl/CMakeLists.txt (+5/-0)
tests/core/internal/persistent_string_cache_impl/persistent_string_cache_impl_test.cpp (+1986/-0)
tests/core/persistent_cache/CMakeLists.txt (+5/-0)
tests/core/persistent_cache/persistent_cache_test.cpp (+1413/-0)
tests/core/persistent_string_cache/CMakeLists.txt (+11/-0)
tests/core/persistent_string_cache/persistent_string_cache_test.cpp (+469/-0)
tests/core/persistent_string_cache/speed_test.cpp (+212/-0)
tests/dbus/CMakeLists.txt (+12/-0)
tests/dbus/dbus_test.cpp (+558/-0)
tests/download/CMakeLists.txt (+11/-0)
tests/download/download_test.cpp (+216/-135)
tests/file_io/CMakeLists.txt (+4/-0)
tests/file_io/file_io_test.cpp (+155/-0)
tests/gobj_ptr/CMakeLists.txt (+3/-0)
tests/gobj_ptr/gobj_ptr_test.cpp (+166/-129)
tests/headers/CMakeLists.txt (+45/-0)
tests/headers/compile_headers.py (+169/-0)
tests/image/CMakeLists.txt (+4/-0)
tests/image/image_test.cpp (+368/-0)
tests/media/bad_image.jpg (+1/-0)
tests/mediaartcachetest.cpp (+0/-169)
tests/qml/CMakeLists.txt (+11/-0)
tests/qml/Fixture.qml (+109/-0)
tests/qml/qml_test.cpp (+78/-0)
tests/qml/tst_albumart.qml (+41/-66)
tests/qml/tst_embedded_albumart.qml (+10/-0)
tests/qml/tst_photo.qml (+61/-0)
tests/safe_strerror/CMakeLists.txt (+4/-0)
tests/safe_strerror/safe_strerror_test.cpp (+29/-0)
tests/server/images/artist_album.png (+1/-0)
tests/server/images/sia_fear.txt (+1/-0)
tests/server/images/sia_fear_album.txt (+1/-0)
tests/server/server.py (+96/-0)
tests/settings/CMakeLists.txt (+4/-0)
tests/settings/settings_test.cpp (+146/-0)
tests/slow-vs-thumb/CMakeLists.txt (+11/-0)
tests/slow-vs-thumb/slow-vs-thumb_test.cpp (+63/-0)
tests/slow-vs-thumb/slow/vs-thumb (+3/-0)
tests/testsetup.h.in (+29/-3)
tests/thumbnailer-admin/CMakeLists.txt (+16/-0)
tests/thumbnailer-admin/thumbnailer-admin_test.cpp (+616/-0)
tests/thumbnailer/CMakeLists.txt (+14/-0)
tests/thumbnailer/thumbnailer_test.cpp (+902/-0)
tests/thumbnailer/vs-thumb-crash/vs-thumb (+3/-0)
tests/thumbnailer/vs-thumb-exit-1/vs-thumb (+3/-0)
tests/thumbnailer/vs-thumb-exit-2/vs-thumb (+3/-0)
tests/thumbnailer/vs-thumb-exit-99/vs-thumb (+3/-0)
tests/utils/CMakeLists.txt (+34/-0)
tests/utils/artserver.cpp (+59/-0)
tests/utils/artserver.h (+34/-0)
tests/utils/dbusserver.cpp (+64/-0)
tests/utils/dbusserver.h (+48/-0)
tests/vs-thumb/CMakeLists.txt (+9/-0)
tests/vs-thumb/vs-thumb_test.cpp (+223/-0)
tests/whitespace/CMakeLists.txt (+9/-0)
tests/whitespace/check_whitespace.py (+114/-0)
tools/CMakeLists.txt (+0/-14)
tools/cachetool.cpp (+0/-37)
tools/imdump.cpp (+0/-34)
tools/lastfmtest.cpp (+0/-31)
tools/parse-settings.py (+123/-0)
tools/scaler.cpp (+0/-38)
tools/ubuntuservertest.cpp (+0/-28)
tsan-suppress (+2/-0)
valgrind-suppress (+133/-0)
To merge this branch: bzr merge lp:~jamesh/thumbnailer/landing-20150622
Reviewer Review Type Date Requested Status
Michi Henning (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+262567@code.launchpad.net

Commit message

Merge lp:thumbnailer/devel r240 into trunk.

Description of the change

Merge lp:thumbnailer/devel r231 into trunk.

I've used lp:~ci-train-bot/thumbnailer/thumbnailer-ubuntu-wily-proposed as a base for this branch, since the last landing doesn't seem to have made it to trunk. I've also integrated Adam Conrad's packaging fix that was made on top of wily-proposed outside of CI prior to the merge.

I've summarised the most visible changes in the Debian changelog (I can add more if you want).

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michi Henning (michihenning) wrote :

Looking good to me. Works well on the phone, aside from gstreamer problems. But, even when gstreamer does something stupid, we recover well.

review: Approve
127. By James Henstridge

Merge from devel

128. By James Henstridge

Update Debian changelog.

Revision history for this message
Victor Thompson (vthompson) wrote :

I'm still seeing the same issue with regard to thumbnails timing out [1]

Music app log [2]

Syslog [3]

1 - https://www.youtube.com/watch?v=LBwUGe8n1Hs
2 - http://paste.ubuntu.com/11767442/
3 - http://paste.ubuntu.com/11767445/

Revision history for this message
Victor Thompson (vthompson) wrote :

Actually, disregard my last comment. Upon restarting the device the thumbnails are starting to show up without immediately timing out. Once the thumbnails are generated the first time, they appear to re-generate from cache (I assume) immediately--whereas the version in the device images would slowly generate them each time and seemingly block on something being processed.

Revision history for this message
James Henstridge (jamesh) wrote :

My guess is that your app was running with the new QML plugin but talking to the old thumbnailer-service. There were some changes to the API as part of the rewrite (to support requesting thumbnails of arbitrary size rather than the fixed set of sizes), so the placeholder images would be due to the broken D-Bus method calls. Rebooting would have made sure you were on the new code.

One of the main causes of the old serialised behaviour was due to the old QQuickImageProvider API, which requested thumbnails one by one on a single worker thread. With this branch, we're using the new QQuickAsyncImageProvider API so we can start multiple thumbnail jobs in parallel.

Revision history for this message
Michi Henning (michihenning) wrote :

Hi Victor, thanks heaps for helping to test this!

If you want to see what's going on with the cache, you can run a tail -f on ~/.cache/upstart/dbus.log. All the thumbnailer messages end up in there. If you want to test with an empty cache, you can run

thumbnailer-admin clear

This completely wipes the cached thumbnails. You can pull out to lots of statistics for the three internal caches with

thumbnailer-admin stats -v

129. By James Henstridge

Merge from devel

Revision history for this message
Michi Henning (michihenning) wrote :

Yes, thank you!

review: Approve
130. By James Henstridge

Merge lp:thumbnailer/devel r240

Revision history for this message
Michi Henning (michihenning) wrote :

Yes, definitely!

review: Approve
131. By James Henstridge

Merge lp:thumbnailer/devel r241

Revision history for this message
Michi Henning (michihenning) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-09-25 09:47:05 +0000
3+++ CMakeLists.txt 2015-07-14 06:30:34 +0000
4@@ -1,27 +1,82 @@
5 project(thumbnailer C CXX)
6-cmake_minimum_required(VERSION 2.8.7)
7-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra")
8-
9-include(CheckCXXCompilerFlag)
10-check_cxx_compiler_flag(-std=c++11 HAS_C11)
11-# Precise's GCC is too old to have -std=c++11
12-if(HAS_C11)
13-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
14-else()
15-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Dfinal=")
16-endif()
17-
18-set(SO_VERSION_MAJOR "1")
19-set(SO_VERSION_MINOR "1")
20-set(SO_VERSION_PATCH "0")
21-
22-set(SO_VERSION "${SO_VERSION_MAJOR}.${SO_VERSION_MINOR}.${SO_VERSION_PATCH}")
23-
24-# Increment this manually whenever breaking ABI.
25-# http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN135
26-set(ABI_VERSION 0)
27-
28-include(cmake/coverage.cmake)
29+
30+set(CMAKE_INCLUDE_CURRENT_DIR ON)
31+
32+cmake_minimum_required(VERSION 2.8.11)
33+
34+# Suppress complaints by cmake about COMPILE_DEFINITIONS_<Config> caused by qt5 cmake macros.
35+cmake_policy(SET CMP0043 OLD)
36+
37+string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower) # Build types should always be lower case
38+
39+set(ACCEPTED_BUILD_TYPES "" none release debug relwithdebinfo coverage)
40+list(FIND ACCEPTED_BUILD_TYPES "${cmake_build_type_lower}" IS_BUILD_TYPE_ACCEPTED)
41+if(${IS_BUILD_TYPE_ACCEPTED} EQUAL -1)
42+ message(FATAL_ERROR "Invalid CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}\nValid types are: ${ACCEPTED_BUILD_TYPES}")
43+endif()
44+
45+set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
46+
47+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -Wall -pedantic -Wextra")
48+
49+# Some additional warnings not included by the general flags set above.
50+set(EXTRA_C_WARNINGS "-Wcast-align -Wcast-qual -Wformat -Wredundant-decls -Wswitch-default")
51+set(EXTRA_CXX_WARNINGS "-Wnon-virtual-dtor -Wctor-dtor-privacy -Wold-style-cast")
52+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_WARNINGS} ${EXTRA_CXX_WARNINGS}")
53+
54+# By default, for release builds, warnings become hard errors.
55+if ("${cmake_build_type_lower}" STREQUAL "release" OR "${cmake_build_type_lower}" STREQUAL "relwithdebinfo")
56+ option(Werror "Treat warnings as errors" ON)
57+else()
58+ option(Werror "Treat warnings as errors" OFF)
59+endif()
60+
61+# If warnings are errors, don't error on deprecated declarations.
62+if (${Werror})
63+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
64+ if ("${cmake_build_type_lower}" STREQUAL "release" OR "${cmake_build_type_lower}" STREQUAL "relwithdebinfo")
65+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations")
66+ endif()
67+endif()
68+
69+add_definitions(-DQT_NO_KEYWORDS)
70+
71+# Flags for thread/address sanitizer
72+set(SANITIZER "" CACHE STRING "Build with -fsanitize=<value> (legal values: thread, address)")
73+
74+if ("${SANITIZER}" STREQUAL "")
75+ # Do nothing
76+elseif (${SANITIZER} STREQUAL "thread")
77+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer -g")
78+elseif (${SANITIZER} STREQUAL "address")
79+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -g")
80+else()
81+ message(FATAL_ERROR "Invalid SANITIZER setting: ${SANITIZER}")
82+endif()
83+
84+# Some tests are slow, so make it possible not to run them
85+# during day-to-day development.
86+option(slowtests "Run slow tests" ON)
87+
88+# Definitions for testing with valgrind.
89+
90+configure_file(CTestCustom.cmake.in CTestCustom.cmake) # Tests in CTestCustom.cmake are skipped for valgrind
91+
92+find_program(MEMORYCHECK_COMMAND NAMES valgrind)
93+if (MEMORYCHECK_COMMAND)
94+ set(MEMORYCHECK_COMMAND_OPTIONS
95+ "--suppressions=${CMAKE_SOURCE_DIR}/valgrind-suppress --errors-for-leak-kinds=definite --show-leak-kinds=definite --leak-check=full --num-callers=50 --error-exitcode=3"
96+ )
97+ add_custom_target(valgrind DEPENDS NightlyMemCheck)
98+else()
99+ message(WARNING "Cannot find valgrind: valgrind target will not be available")
100+endif()
101+
102+include(CTest)
103+enable_testing()
104+
105+include(EnableCoverageReport)
106+
107 include(cmake/UseGSettings.cmake)
108
109 include(GNUInstallDirs)
110@@ -29,27 +84,46 @@
111 set(SHARE_PRIV_DIR ${CMAKE_INSTALL_LIBDIR}/thumbnailer)
112 set(SHARE_PRIV_ABS ${CMAKE_INSTALL_PREFIX}/${SHARE_PRIV_DIR})
113
114+find_package(Boost COMPONENTS filesystem regex system REQUIRED)
115 find_package(Threads REQUIRED)
116 find_package(Qt5Core REQUIRED)
117+find_package(Qt5DBus REQUIRED)
118+
119 include(FindPkgConfig)
120-pkg_check_modules(GST_DEPS REQUIRED gstreamer-1.0 gstreamer-plugins-base-1.0 gstreamer-pbutils-1.0 gstreamer-app-1.0)
121+pkg_check_modules(GST_DEPS REQUIRED gstreamer-1.0 gstreamer-plugins-base-1.0 gstreamer-tag-1.0)
122+pkg_check_modules(GOBJ_DEPS REQUIRED gobject-2.0)
123 pkg_check_modules(GIO_DEPS REQUIRED gio-2.0 gio-unix-2.0)
124 pkg_check_modules(IMG_DEPS REQUIRED gdk-pixbuf-2.0 libexif)
125-pkg_check_modules(SOUP_DEPS REQUIRED libsoup-2.4)
126-pkg_check_modules(XML_DEPS REQUIRED libxml-2.0)
127+pkg_check_modules(UNITY_API_DEPS REQUIRED libunity-api)
128+pkg_check_modules(APPARMOR_DEPS REQUIRED libapparmor)
129
130 include_directories(${GST_DEPS_INCLUDE_DIRS})
131+include_directories(${GOBJ_DEPS_INCLUDE_DIRS})
132 include_directories(${GIO_DEPS_INCLUDE_DIRS})
133 include_directories(${IMG_DEPS_INCLUDE_DIRS})
134-include_directories(${SOUP_DEPS_INCLUDE_DIRS})
135-include_directories(${XML_DEPS_INCLUDE_DIRS})
136+include_directories(${UNITY_API_DEPS_INCLUDE_DIRS})
137+include_directories(${APPARMOR_DEPS_INCLUDE_DIRS})
138 include_directories(include)
139 include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
140
141-enable_testing()
142 add_subdirectory(src)
143 add_subdirectory(data)
144-add_subdirectory(plugins/Ubuntu/Thumbnailer)
145+add_subdirectory(plugins/Ubuntu/Thumbnailer.0.1)
146 add_subdirectory(tests)
147-add_subdirectory(tools)
148 add_subdirectory(include)
149+
150+enable_coverage_report(
151+ TARGETS
152+ thumbnailer
153+ thumbnailer-admin
154+ thumbnailer-service
155+ thumbnailer-qml
156+ vs-thumb
157+ testutils
158+ FILTER
159+ ${CMAKE_SOURCE_DIR}/include/core/*
160+ ${CMAKE_SOURCE_DIR}/tests/*
161+ ${CMAKE_BINARY_DIR}/*
162+ TESTS
163+ ${UNIT_TEST_TARGETS}
164+)
165
166=== added file 'COPYING.GPL'
167--- COPYING.GPL 1970-01-01 00:00:00 +0000
168+++ COPYING.GPL 2015-07-14 06:30:34 +0000
169@@ -0,0 +1,674 @@
170+ GNU GENERAL PUBLIC LICENSE
171+ Version 3, 29 June 2007
172+
173+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
174+ Everyone is permitted to copy and distribute verbatim copies
175+ of this license document, but changing it is not allowed.
176+
177+ Preamble
178+
179+ The GNU General Public License is a free, copyleft license for
180+software and other kinds of works.
181+
182+ The licenses for most software and other practical works are designed
183+to take away your freedom to share and change the works. By contrast,
184+the GNU General Public License is intended to guarantee your freedom to
185+share and change all versions of a program--to make sure it remains free
186+software for all its users. We, the Free Software Foundation, use the
187+GNU General Public License for most of our software; it applies also to
188+any other work released this way by its authors. You can apply it to
189+your programs, too.
190+
191+ When we speak of free software, we are referring to freedom, not
192+price. Our General Public Licenses are designed to make sure that you
193+have the freedom to distribute copies of free software (and charge for
194+them if you wish), that you receive source code or can get it if you
195+want it, that you can change the software or use pieces of it in new
196+free programs, and that you know you can do these things.
197+
198+ To protect your rights, we need to prevent others from denying you
199+these rights or asking you to surrender the rights. Therefore, you have
200+certain responsibilities if you distribute copies of the software, or if
201+you modify it: responsibilities to respect the freedom of others.
202+
203+ For example, if you distribute copies of such a program, whether
204+gratis or for a fee, you must pass on to the recipients the same
205+freedoms that you received. You must make sure that they, too, receive
206+or can get the source code. And you must show them these terms so they
207+know their rights.
208+
209+ Developers that use the GNU GPL protect your rights with two steps:
210+(1) assert copyright on the software, and (2) offer you this License
211+giving you legal permission to copy, distribute and/or modify it.
212+
213+ For the developers' and authors' protection, the GPL clearly explains
214+that there is no warranty for this free software. For both users' and
215+authors' sake, the GPL requires that modified versions be marked as
216+changed, so that their problems will not be attributed erroneously to
217+authors of previous versions.
218+
219+ Some devices are designed to deny users access to install or run
220+modified versions of the software inside them, although the manufacturer
221+can do so. This is fundamentally incompatible with the aim of
222+protecting users' freedom to change the software. The systematic
223+pattern of such abuse occurs in the area of products for individuals to
224+use, which is precisely where it is most unacceptable. Therefore, we
225+have designed this version of the GPL to prohibit the practice for those
226+products. If such problems arise substantially in other domains, we
227+stand ready to extend this provision to those domains in future versions
228+of the GPL, as needed to protect the freedom of users.
229+
230+ Finally, every program is threatened constantly by software patents.
231+States should not allow patents to restrict development and use of
232+software on general-purpose computers, but in those that do, we wish to
233+avoid the special danger that patents applied to a free program could
234+make it effectively proprietary. To prevent this, the GPL assures that
235+patents cannot be used to render the program non-free.
236+
237+ The precise terms and conditions for copying, distribution and
238+modification follow.
239+
240+ TERMS AND CONDITIONS
241+
242+ 0. Definitions.
243+
244+ "This License" refers to version 3 of the GNU General Public License.
245+
246+ "Copyright" also means copyright-like laws that apply to other kinds of
247+works, such as semiconductor masks.
248+
249+ "The Program" refers to any copyrightable work licensed under this
250+License. Each licensee is addressed as "you". "Licensees" and
251+"recipients" may be individuals or organizations.
252+
253+ To "modify" a work means to copy from or adapt all or part of the work
254+in a fashion requiring copyright permission, other than the making of an
255+exact copy. The resulting work is called a "modified version" of the
256+earlier work or a work "based on" the earlier work.
257+
258+ A "covered work" means either the unmodified Program or a work based
259+on the Program.
260+
261+ To "propagate" a work means to do anything with it that, without
262+permission, would make you directly or secondarily liable for
263+infringement under applicable copyright law, except executing it on a
264+computer or modifying a private copy. Propagation includes copying,
265+distribution (with or without modification), making available to the
266+public, and in some countries other activities as well.
267+
268+ To "convey" a work means any kind of propagation that enables other
269+parties to make or receive copies. Mere interaction with a user through
270+a computer network, with no transfer of a copy, is not conveying.
271+
272+ An interactive user interface displays "Appropriate Legal Notices"
273+to the extent that it includes a convenient and prominently visible
274+feature that (1) displays an appropriate copyright notice, and (2)
275+tells the user that there is no warranty for the work (except to the
276+extent that warranties are provided), that licensees may convey the
277+work under this License, and how to view a copy of this License. If
278+the interface presents a list of user commands or options, such as a
279+menu, a prominent item in the list meets this criterion.
280+
281+ 1. Source Code.
282+
283+ The "source code" for a work means the preferred form of the work
284+for making modifications to it. "Object code" means any non-source
285+form of a work.
286+
287+ A "Standard Interface" means an interface that either is an official
288+standard defined by a recognized standards body, or, in the case of
289+interfaces specified for a particular programming language, one that
290+is widely used among developers working in that language.
291+
292+ The "System Libraries" of an executable work include anything, other
293+than the work as a whole, that (a) is included in the normal form of
294+packaging a Major Component, but which is not part of that Major
295+Component, and (b) serves only to enable use of the work with that
296+Major Component, or to implement a Standard Interface for which an
297+implementation is available to the public in source code form. A
298+"Major Component", in this context, means a major essential component
299+(kernel, window system, and so on) of the specific operating system
300+(if any) on which the executable work runs, or a compiler used to
301+produce the work, or an object code interpreter used to run it.
302+
303+ The "Corresponding Source" for a work in object code form means all
304+the source code needed to generate, install, and (for an executable
305+work) run the object code and to modify the work, including scripts to
306+control those activities. However, it does not include the work's
307+System Libraries, or general-purpose tools or generally available free
308+programs which are used unmodified in performing those activities but
309+which are not part of the work. For example, Corresponding Source
310+includes interface definition files associated with source files for
311+the work, and the source code for shared libraries and dynamically
312+linked subprograms that the work is specifically designed to require,
313+such as by intimate data communication or control flow between those
314+subprograms and other parts of the work.
315+
316+ The Corresponding Source need not include anything that users
317+can regenerate automatically from other parts of the Corresponding
318+Source.
319+
320+ The Corresponding Source for a work in source code form is that
321+same work.
322+
323+ 2. Basic Permissions.
324+
325+ All rights granted under this License are granted for the term of
326+copyright on the Program, and are irrevocable provided the stated
327+conditions are met. This License explicitly affirms your unlimited
328+permission to run the unmodified Program. The output from running a
329+covered work is covered by this License only if the output, given its
330+content, constitutes a covered work. This License acknowledges your
331+rights of fair use or other equivalent, as provided by copyright law.
332+
333+ You may make, run and propagate covered works that you do not
334+convey, without conditions so long as your license otherwise remains
335+in force. You may convey covered works to others for the sole purpose
336+of having them make modifications exclusively for you, or provide you
337+with facilities for running those works, provided that you comply with
338+the terms of this License in conveying all material for which you do
339+not control copyright. Those thus making or running the covered works
340+for you must do so exclusively on your behalf, under your direction
341+and control, on terms that prohibit them from making any copies of
342+your copyrighted material outside their relationship with you.
343+
344+ Conveying under any other circumstances is permitted solely under
345+the conditions stated below. Sublicensing is not allowed; section 10
346+makes it unnecessary.
347+
348+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
349+
350+ No covered work shall be deemed part of an effective technological
351+measure under any applicable law fulfilling obligations under article
352+11 of the WIPO copyright treaty adopted on 20 December 1996, or
353+similar laws prohibiting or restricting circumvention of such
354+measures.
355+
356+ When you convey a covered work, you waive any legal power to forbid
357+circumvention of technological measures to the extent such circumvention
358+is effected by exercising rights under this License with respect to
359+the covered work, and you disclaim any intention to limit operation or
360+modification of the work as a means of enforcing, against the work's
361+users, your or third parties' legal rights to forbid circumvention of
362+technological measures.
363+
364+ 4. Conveying Verbatim Copies.
365+
366+ You may convey verbatim copies of the Program's source code as you
367+receive it, in any medium, provided that you conspicuously and
368+appropriately publish on each copy an appropriate copyright notice;
369+keep intact all notices stating that this License and any
370+non-permissive terms added in accord with section 7 apply to the code;
371+keep intact all notices of the absence of any warranty; and give all
372+recipients a copy of this License along with the Program.
373+
374+ You may charge any price or no price for each copy that you convey,
375+and you may offer support or warranty protection for a fee.
376+
377+ 5. Conveying Modified Source Versions.
378+
379+ You may convey a work based on the Program, or the modifications to
380+produce it from the Program, in the form of source code under the
381+terms of section 4, provided that you also meet all of these conditions:
382+
383+ a) The work must carry prominent notices stating that you modified
384+ it, and giving a relevant date.
385+
386+ b) The work must carry prominent notices stating that it is
387+ released under this License and any conditions added under section
388+ 7. This requirement modifies the requirement in section 4 to
389+ "keep intact all notices".
390+
391+ c) You must license the entire work, as a whole, under this
392+ License to anyone who comes into possession of a copy. This
393+ License will therefore apply, along with any applicable section 7
394+ additional terms, to the whole of the work, and all its parts,
395+ regardless of how they are packaged. This License gives no
396+ permission to license the work in any other way, but it does not
397+ invalidate such permission if you have separately received it.
398+
399+ d) If the work has interactive user interfaces, each must display
400+ Appropriate Legal Notices; however, if the Program has interactive
401+ interfaces that do not display Appropriate Legal Notices, your
402+ work need not make them do so.
403+
404+ A compilation of a covered work with other separate and independent
405+works, which are not by their nature extensions of the covered work,
406+and which are not combined with it such as to form a larger program,
407+in or on a volume of a storage or distribution medium, is called an
408+"aggregate" if the compilation and its resulting copyright are not
409+used to limit the access or legal rights of the compilation's users
410+beyond what the individual works permit. Inclusion of a covered work
411+in an aggregate does not cause this License to apply to the other
412+parts of the aggregate.
413+
414+ 6. Conveying Non-Source Forms.
415+
416+ You may convey a covered work in object code form under the terms
417+of sections 4 and 5, provided that you also convey the
418+machine-readable Corresponding Source under the terms of this License,
419+in one of these ways:
420+
421+ a) Convey the object code in, or embodied in, a physical product
422+ (including a physical distribution medium), accompanied by the
423+ Corresponding Source fixed on a durable physical medium
424+ customarily used for software interchange.
425+
426+ b) Convey the object code in, or embodied in, a physical product
427+ (including a physical distribution medium), accompanied by a
428+ written offer, valid for at least three years and valid for as
429+ long as you offer spare parts or customer support for that product
430+ model, to give anyone who possesses the object code either (1) a
431+ copy of the Corresponding Source for all the software in the
432+ product that is covered by this License, on a durable physical
433+ medium customarily used for software interchange, for a price no
434+ more than your reasonable cost of physically performing this
435+ conveying of source, or (2) access to copy the
436+ Corresponding Source from a network server at no charge.
437+
438+ c) Convey individual copies of the object code with a copy of the
439+ written offer to provide the Corresponding Source. This
440+ alternative is allowed only occasionally and noncommercially, and
441+ only if you received the object code with such an offer, in accord
442+ with subsection 6b.
443+
444+ d) Convey the object code by offering access from a designated
445+ place (gratis or for a charge), and offer equivalent access to the
446+ Corresponding Source in the same way through the same place at no
447+ further charge. You need not require recipients to copy the
448+ Corresponding Source along with the object code. If the place to
449+ copy the object code is a network server, the Corresponding Source
450+ may be on a different server (operated by you or a third party)
451+ that supports equivalent copying facilities, provided you maintain
452+ clear directions next to the object code saying where to find the
453+ Corresponding Source. Regardless of what server hosts the
454+ Corresponding Source, you remain obligated to ensure that it is
455+ available for as long as needed to satisfy these requirements.
456+
457+ e) Convey the object code using peer-to-peer transmission, provided
458+ you inform other peers where the object code and Corresponding
459+ Source of the work are being offered to the general public at no
460+ charge under subsection 6d.
461+
462+ A separable portion of the object code, whose source code is excluded
463+from the Corresponding Source as a System Library, need not be
464+included in conveying the object code work.
465+
466+ A "User Product" is either (1) a "consumer product", which means any
467+tangible personal property which is normally used for personal, family,
468+or household purposes, or (2) anything designed or sold for incorporation
469+into a dwelling. In determining whether a product is a consumer product,
470+doubtful cases shall be resolved in favor of coverage. For a particular
471+product received by a particular user, "normally used" refers to a
472+typical or common use of that class of product, regardless of the status
473+of the particular user or of the way in which the particular user
474+actually uses, or expects or is expected to use, the product. A product
475+is a consumer product regardless of whether the product has substantial
476+commercial, industrial or non-consumer uses, unless such uses represent
477+the only significant mode of use of the product.
478+
479+ "Installation Information" for a User Product means any methods,
480+procedures, authorization keys, or other information required to install
481+and execute modified versions of a covered work in that User Product from
482+a modified version of its Corresponding Source. The information must
483+suffice to ensure that the continued functioning of the modified object
484+code is in no case prevented or interfered with solely because
485+modification has been made.
486+
487+ If you convey an object code work under this section in, or with, or
488+specifically for use in, a User Product, and the conveying occurs as
489+part of a transaction in which the right of possession and use of the
490+User Product is transferred to the recipient in perpetuity or for a
491+fixed term (regardless of how the transaction is characterized), the
492+Corresponding Source conveyed under this section must be accompanied
493+by the Installation Information. But this requirement does not apply
494+if neither you nor any third party retains the ability to install
495+modified object code on the User Product (for example, the work has
496+been installed in ROM).
497+
498+ The requirement to provide Installation Information does not include a
499+requirement to continue to provide support service, warranty, or updates
500+for a work that has been modified or installed by the recipient, or for
501+the User Product in which it has been modified or installed. Access to a
502+network may be denied when the modification itself materially and
503+adversely affects the operation of the network or violates the rules and
504+protocols for communication across the network.
505+
506+ Corresponding Source conveyed, and Installation Information provided,
507+in accord with this section must be in a format that is publicly
508+documented (and with an implementation available to the public in
509+source code form), and must require no special password or key for
510+unpacking, reading or copying.
511+
512+ 7. Additional Terms.
513+
514+ "Additional permissions" are terms that supplement the terms of this
515+License by making exceptions from one or more of its conditions.
516+Additional permissions that are applicable to the entire Program shall
517+be treated as though they were included in this License, to the extent
518+that they are valid under applicable law. If additional permissions
519+apply only to part of the Program, that part may be used separately
520+under those permissions, but the entire Program remains governed by
521+this License without regard to the additional permissions.
522+
523+ When you convey a copy of a covered work, you may at your option
524+remove any additional permissions from that copy, or from any part of
525+it. (Additional permissions may be written to require their own
526+removal in certain cases when you modify the work.) You may place
527+additional permissions on material, added by you to a covered work,
528+for which you have or can give appropriate copyright permission.
529+
530+ Notwithstanding any other provision of this License, for material you
531+add to a covered work, you may (if authorized by the copyright holders of
532+that material) supplement the terms of this License with terms:
533+
534+ a) Disclaiming warranty or limiting liability differently from the
535+ terms of sections 15 and 16 of this License; or
536+
537+ b) Requiring preservation of specified reasonable legal notices or
538+ author attributions in that material or in the Appropriate Legal
539+ Notices displayed by works containing it; or
540+
541+ c) Prohibiting misrepresentation of the origin of that material, or
542+ requiring that modified versions of such material be marked in
543+ reasonable ways as different from the original version; or
544+
545+ d) Limiting the use for publicity purposes of names of licensors or
546+ authors of the material; or
547+
548+ e) Declining to grant rights under trademark law for use of some
549+ trade names, trademarks, or service marks; or
550+
551+ f) Requiring indemnification of licensors and authors of that
552+ material by anyone who conveys the material (or modified versions of
553+ it) with contractual assumptions of liability to the recipient, for
554+ any liability that these contractual assumptions directly impose on
555+ those licensors and authors.
556+
557+ All other non-permissive additional terms are considered "further
558+restrictions" within the meaning of section 10. If the Program as you
559+received it, or any part of it, contains a notice stating that it is
560+governed by this License along with a term that is a further
561+restriction, you may remove that term. If a license document contains
562+a further restriction but permits relicensing or conveying under this
563+License, you may add to a covered work material governed by the terms
564+of that license document, provided that the further restriction does
565+not survive such relicensing or conveying.
566+
567+ If you add terms to a covered work in accord with this section, you
568+must place, in the relevant source files, a statement of the
569+additional terms that apply to those files, or a notice indicating
570+where to find the applicable terms.
571+
572+ Additional terms, permissive or non-permissive, may be stated in the
573+form of a separately written license, or stated as exceptions;
574+the above requirements apply either way.
575+
576+ 8. Termination.
577+
578+ You may not propagate or modify a covered work except as expressly
579+provided under this License. Any attempt otherwise to propagate or
580+modify it is void, and will automatically terminate your rights under
581+this License (including any patent licenses granted under the third
582+paragraph of section 11).
583+
584+ However, if you cease all violation of this License, then your
585+license from a particular copyright holder is reinstated (a)
586+provisionally, unless and until the copyright holder explicitly and
587+finally terminates your license, and (b) permanently, if the copyright
588+holder fails to notify you of the violation by some reasonable means
589+prior to 60 days after the cessation.
590+
591+ Moreover, your license from a particular copyright holder is
592+reinstated permanently if the copyright holder notifies you of the
593+violation by some reasonable means, this is the first time you have
594+received notice of violation of this License (for any work) from that
595+copyright holder, and you cure the violation prior to 30 days after
596+your receipt of the notice.
597+
598+ Termination of your rights under this section does not terminate the
599+licenses of parties who have received copies or rights from you under
600+this License. If your rights have been terminated and not permanently
601+reinstated, you do not qualify to receive new licenses for the same
602+material under section 10.
603+
604+ 9. Acceptance Not Required for Having Copies.
605+
606+ You are not required to accept this License in order to receive or
607+run a copy of the Program. Ancillary propagation of a covered work
608+occurring solely as a consequence of using peer-to-peer transmission
609+to receive a copy likewise does not require acceptance. However,
610+nothing other than this License grants you permission to propagate or
611+modify any covered work. These actions infringe copyright if you do
612+not accept this License. Therefore, by modifying or propagating a
613+covered work, you indicate your acceptance of this License to do so.
614+
615+ 10. Automatic Licensing of Downstream Recipients.
616+
617+ Each time you convey a covered work, the recipient automatically
618+receives a license from the original licensors, to run, modify and
619+propagate that work, subject to this License. You are not responsible
620+for enforcing compliance by third parties with this License.
621+
622+ An "entity transaction" is a transaction transferring control of an
623+organization, or substantially all assets of one, or subdividing an
624+organization, or merging organizations. If propagation of a covered
625+work results from an entity transaction, each party to that
626+transaction who receives a copy of the work also receives whatever
627+licenses to the work the party's predecessor in interest had or could
628+give under the previous paragraph, plus a right to possession of the
629+Corresponding Source of the work from the predecessor in interest, if
630+the predecessor has it or can get it with reasonable efforts.
631+
632+ You may not impose any further restrictions on the exercise of the
633+rights granted or affirmed under this License. For example, you may
634+not impose a license fee, royalty, or other charge for exercise of
635+rights granted under this License, and you may not initiate litigation
636+(including a cross-claim or counterclaim in a lawsuit) alleging that
637+any patent claim is infringed by making, using, selling, offering for
638+sale, or importing the Program or any portion of it.
639+
640+ 11. Patents.
641+
642+ A "contributor" is a copyright holder who authorizes use under this
643+License of the Program or a work on which the Program is based. The
644+work thus licensed is called the contributor's "contributor version".
645+
646+ A contributor's "essential patent claims" are all patent claims
647+owned or controlled by the contributor, whether already acquired or
648+hereafter acquired, that would be infringed by some manner, permitted
649+by this License, of making, using, or selling its contributor version,
650+but do not include claims that would be infringed only as a
651+consequence of further modification of the contributor version. For
652+purposes of this definition, "control" includes the right to grant
653+patent sublicenses in a manner consistent with the requirements of
654+this License.
655+
656+ Each contributor grants you a non-exclusive, worldwide, royalty-free
657+patent license under the contributor's essential patent claims, to
658+make, use, sell, offer for sale, import and otherwise run, modify and
659+propagate the contents of its contributor version.
660+
661+ In the following three paragraphs, a "patent license" is any express
662+agreement or commitment, however denominated, not to enforce a patent
663+(such as an express permission to practice a patent or covenant not to
664+sue for patent infringement). To "grant" such a patent license to a
665+party means to make such an agreement or commitment not to enforce a
666+patent against the party.
667+
668+ If you convey a covered work, knowingly relying on a patent license,
669+and the Corresponding Source of the work is not available for anyone
670+to copy, free of charge and under the terms of this License, through a
671+publicly available network server or other readily accessible means,
672+then you must either (1) cause the Corresponding Source to be so
673+available, or (2) arrange to deprive yourself of the benefit of the
674+patent license for this particular work, or (3) arrange, in a manner
675+consistent with the requirements of this License, to extend the patent
676+license to downstream recipients. "Knowingly relying" means you have
677+actual knowledge that, but for the patent license, your conveying the
678+covered work in a country, or your recipient's use of the covered work
679+in a country, would infringe one or more identifiable patents in that
680+country that you have reason to believe are valid.
681+
682+ If, pursuant to or in connection with a single transaction or
683+arrangement, you convey, or propagate by procuring conveyance of, a
684+covered work, and grant a patent license to some of the parties
685+receiving the covered work authorizing them to use, propagate, modify
686+or convey a specific copy of the covered work, then the patent license
687+you grant is automatically extended to all recipients of the covered
688+work and works based on it.
689+
690+ A patent license is "discriminatory" if it does not include within
691+the scope of its coverage, prohibits the exercise of, or is
692+conditioned on the non-exercise of one or more of the rights that are
693+specifically granted under this License. You may not convey a covered
694+work if you are a party to an arrangement with a third party that is
695+in the business of distributing software, under which you make payment
696+to the third party based on the extent of your activity of conveying
697+the work, and under which the third party grants, to any of the
698+parties who would receive the covered work from you, a discriminatory
699+patent license (a) in connection with copies of the covered work
700+conveyed by you (or copies made from those copies), or (b) primarily
701+for and in connection with specific products or compilations that
702+contain the covered work, unless you entered into that arrangement,
703+or that patent license was granted, prior to 28 March 2007.
704+
705+ Nothing in this License shall be construed as excluding or limiting
706+any implied license or other defenses to infringement that may
707+otherwise be available to you under applicable patent law.
708+
709+ 12. No Surrender of Others' Freedom.
710+
711+ If conditions are imposed on you (whether by court order, agreement or
712+otherwise) that contradict the conditions of this License, they do not
713+excuse you from the conditions of this License. If you cannot convey a
714+covered work so as to satisfy simultaneously your obligations under this
715+License and any other pertinent obligations, then as a consequence you may
716+not convey it at all. For example, if you agree to terms that obligate you
717+to collect a royalty for further conveying from those to whom you convey
718+the Program, the only way you could satisfy both those terms and this
719+License would be to refrain entirely from conveying the Program.
720+
721+ 13. Use with the GNU Affero General Public License.
722+
723+ Notwithstanding any other provision of this License, you have
724+permission to link or combine any covered work with a work licensed
725+under version 3 of the GNU Affero General Public License into a single
726+combined work, and to convey the resulting work. The terms of this
727+License will continue to apply to the part which is the covered work,
728+but the special requirements of the GNU Affero General Public License,
729+section 13, concerning interaction through a network will apply to the
730+combination as such.
731+
732+ 14. Revised Versions of this License.
733+
734+ The Free Software Foundation may publish revised and/or new versions of
735+the GNU General Public License from time to time. Such new versions will
736+be similar in spirit to the present version, but may differ in detail to
737+address new problems or concerns.
738+
739+ Each version is given a distinguishing version number. If the
740+Program specifies that a certain numbered version of the GNU General
741+Public License "or any later version" applies to it, you have the
742+option of following the terms and conditions either of that numbered
743+version or of any later version published by the Free Software
744+Foundation. If the Program does not specify a version number of the
745+GNU General Public License, you may choose any version ever published
746+by the Free Software Foundation.
747+
748+ If the Program specifies that a proxy can decide which future
749+versions of the GNU General Public License can be used, that proxy's
750+public statement of acceptance of a version permanently authorizes you
751+to choose that version for the Program.
752+
753+ Later license versions may give you additional or different
754+permissions. However, no additional obligations are imposed on any
755+author or copyright holder as a result of your choosing to follow a
756+later version.
757+
758+ 15. Disclaimer of Warranty.
759+
760+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
761+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
762+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
763+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
764+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
765+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
766+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
767+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
768+
769+ 16. Limitation of Liability.
770+
771+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
772+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
773+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
774+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
775+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
776+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
777+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
778+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
779+SUCH DAMAGES.
780+
781+ 17. Interpretation of Sections 15 and 16.
782+
783+ If the disclaimer of warranty and limitation of liability provided
784+above cannot be given local legal effect according to their terms,
785+reviewing courts shall apply local law that most closely approximates
786+an absolute waiver of all civil liability in connection with the
787+Program, unless a warranty or assumption of liability accompanies a
788+copy of the Program in return for a fee.
789+
790+ END OF TERMS AND CONDITIONS
791+
792+ How to Apply These Terms to Your New Programs
793+
794+ If you develop a new program, and you want it to be of the greatest
795+possible use to the public, the best way to achieve this is to make it
796+free software which everyone can redistribute and change under these terms.
797+
798+ To do so, attach the following notices to the program. It is safest
799+to attach them to the start of each source file to most effectively
800+state the exclusion of warranty; and each file should have at least
801+the "copyright" line and a pointer to where the full notice is found.
802+
803+ <one line to give the program's name and a brief idea of what it does.>
804+ Copyright (C) <year> <name of author>
805+
806+ This program is free software: you can redistribute it and/or modify
807+ it under the terms of the GNU General Public License as published by
808+ the Free Software Foundation, either version 3 of the License, or
809+ (at your option) any later version.
810+
811+ This program is distributed in the hope that it will be useful,
812+ but WITHOUT ANY WARRANTY; without even the implied warranty of
813+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
814+ GNU General Public License for more details.
815+
816+ You should have received a copy of the GNU General Public License
817+ along with this program. If not, see <http://www.gnu.org/licenses/>.
818+
819+Also add information on how to contact you by electronic and paper mail.
820+
821+ If the program does terminal interaction, make it output a short
822+notice like this when it starts in an interactive mode:
823+
824+ <program> Copyright (C) <year> <name of author>
825+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
826+ This is free software, and you are welcome to redistribute it
827+ under certain conditions; type `show c' for details.
828+
829+The hypothetical commands `show w' and `show c' should show the appropriate
830+parts of the General Public License. Of course, your program's commands
831+might be different; for a GUI interface, you would use an "about box".
832+
833+ You should also get your employer (if you work as a programmer) or school,
834+if any, to sign a "copyright disclaimer" for the program, if necessary.
835+For more information on this, and how to apply and follow the GNU GPL, see
836+<http://www.gnu.org/licenses/>.
837+
838+ The GNU General Public License does not permit incorporating your program
839+into proprietary programs. If your program is a subroutine library, you
840+may consider it more useful to permit linking proprietary applications with
841+the library. If this is what you want to do, use the GNU Lesser General
842+Public License instead of this License. But first, please read
843+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
844
845=== renamed file 'COPYING' => 'COPYING.LGPL'
846=== added file 'CTestCustom.cmake.in'
847--- CTestCustom.cmake.in 1970-01-01 00:00:00 +0000
848+++ CTestCustom.cmake.in 2015-07-14 06:30:34 +0000
849@@ -0,0 +1,17 @@
850+#
851+# Tests listed here will not be run by the valgrind target,
852+# either because there is not point (we don't want to
853+# test that a python script doesn't leak), or because,
854+# under valgrind, the test runs too slowly to meet
855+# its timing constraints (or crashes valgrind).
856+#
857+
858+SET(CTEST_CUSTOM_MEMCHECK_IGNORE
859+ test_qml # Too many bugs in QML to suppress them selectively
860+ speed
861+ copyright
862+ stand-alone-internal-headers
863+ stand-alone-core-headers
864+ stand-alone-core-internal-headers
865+ whitespace
866+)
867
868=== added file 'HACKING'
869--- HACKING 1970-01-01 00:00:00 +0000
870+++ HACKING 2015-07-14 06:30:34 +0000
871@@ -0,0 +1,121 @@
872+Building the code
873+-----------------
874+
875+By default, the code is built in release mode. To build a debug version, use
876+
877+ $ mkdir builddebug
878+ $ cd builddebug
879+ $ cmake -DCMAKE_BUILD_TYPE=debug ..
880+ $ make
881+
882+For a release version, use -DCMAKE_BUILD_TYPE=release
883+
884+Running the tests
885+-----------------
886+
887+ $ make
888+ $ make test
889+
890+Note that "make test" alone is dangerous because it does not rebuild
891+any tests if either the library or the test files themselves need
892+rebuilding. It's not possible to fix this with cmake because cmake cannot
893+add build dependencies to built-in targets. To make sure that everything
894+is up-to-date, run "make" before running "make test"!
895+
896+To run the tests with valgrind:
897+
898+ $ make valgrind
899+
900+It doesn't make sense for some tests to run them with valgrind. For
901+example, the header compilation tests don't need valgrind because
902+we'd just be testing that Python doesn't leak. There are also some
903+tests that run too slow and time out under valgrind and, occasionally,
904+valgrind crashes for a particular test.
905+
906+There are two ways to suppress tests:
907+
908+You can add a test name to CTestCustom.cmake.in to suppress that
909+test completely. That makes sense for the header compilation tests,
910+for example.
911+
912+If a specific test case in a test program causes a valgrind problem,
913+you can selectively disable a section of code like this:
914+
915+ #include <valgrind/valgrind.h>
916+
917+ if (!RUNNING_ON_VALGRIND)
918+ {
919+ // Code here crashes valgrind...
920+ }
921+
922+That way, the test will still be run as part of the normal "make test"
923+target, but will be ommitted when running "make valgrind".
924+
925+Coverage
926+--------
927+
928+To build with the flags for coverage testing enabled and get coverage:
929+
930+ $ mkdir buildcoverage
931+ $ cd buildcoverage
932+ $ cmake -DCMAKE_BUILD_TYPE=coverage
933+ $ make
934+ $ make test
935+ $ make coverage
936+
937+Unfortunately, it is not possible to get 100% coverage for some files,
938+mainly due to gcc's generation of two destructors for dynamic and non-
939+dynamic instances. For abstract base classes and for classes that
940+prevent stack and static allocation, this causes one of the destructors
941+to be reported as uncovered.
942+
943+There are also issues with some functions in header files that are
944+incorrectly reported as uncovered due to inlining, as well as
945+the impossibility of covering defensive assert(false) statements,
946+such as an assert in the default branch of a switch, where the
947+switch is meant to handle all possible cases explicitly.
948+
949+If you run a binary and get lots of warnings about a "merge mismatch for summaries",
950+this is caused by having made changes to the source that add or remove code
951+that was previously run, so the new coverage output cannot sensibly be merged
952+into the old coverage output. You can get rid of this problem by running
953+
954+ $ make clean-coverage
955+
956+This deletes all the .gcda files, allowing the merge to (sometimes) succeed again.
957+If this doesn't work either, the only remedy is to do a clean build.
958+
959+Code style
960+----------
961+
962+Please maintain the existing coding style. For details
963+on the style, see lp:canonical-client-development-guidelines.
964+
965+We use a format tool that fixes a whole lot of issues
966+regarding code style. See the HACKING file of lp:unity-scopes-api
967+for details on the tool.
968+
969+Thread and address sanitizer
970+----------------------------
971+
972+Set SANITIZER to "thread" or "address" to build with the
973+corresponding sanitizer enabled.
974+
975+Some libraries cause a cause a large number of warnings from
976+thread sanitizer. The tsan-suppress file supresses the benign
977+race conditions we currently know about. To run the tests
978+(from the build directory) with these suppressions
979+enabled, use:
980+
981+ $ TSAN_OPTIONS="suppressions=../tsan-suppress" make test
982+
983+If a test runs too slowly under address sanitizer, you can
984+hide a section of code from address sanitzer with:
985+
986+#if defined(__has_feature)
987+ #if !__has_feature(address_sanitizer)
988+
989+ // Code here takes forever under address sanitizer...
990+
991+ #endif
992+#endif
993
994=== removed file 'cmake/coverage.cmake'
995--- cmake/coverage.cmake 2013-09-30 12:17:23 +0000
996+++ cmake/coverage.cmake 1970-01-01 00:00:00 +0000
997@@ -1,34 +0,0 @@
998-if (CMAKE_BUILD_TYPE MATCHES coverage)
999- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
1000- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
1001- set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage")
1002- set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
1003-
1004- find_program(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin")
1005- if (NOT GCOVR_EXECUTABLE)
1006- message(STATUS "Gcovr binary was not found, can not generate XML coverage info.")
1007- else ()
1008- message(STATUS "Gcovr found, can generate XML coverage info.")
1009- add_custom_target (coverage-xml
1010- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
1011- COMMAND "${GCOVR_EXECUTABLE}" --exclude="test.*" -x -r "${CMAKE_SOURCE_DIR}"
1012- --object-directory=${CMAKE_BINARY_DIR} -o coverage.xml)
1013- endif()
1014-
1015- find_program(LCOV_EXECUTABLE lcov HINTS ${LCOV_ROOT} "${GCOVR_ROOT}/bin")
1016- find_program(GENHTML_EXECUTABLE genhtml HINTS ${GENHTML_ROOT})
1017- if (NOT LCOV_EXECUTABLE)
1018- message(STATUS "Lcov binary was not found, can not generate HTML coverage info.")
1019- else ()
1020- if(NOT GENHTML_EXECUTABLE)
1021- message(STATUS "Genthml binary not found, can not generate HTML coverage info.")
1022- else()
1023- message(STATUS "Lcov and genhtml found, can generate HTML coverage info.")
1024- add_custom_target (coverage-html
1025- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
1026- COMMAND "${LCOV_EXECUTABLE}" --directory ${CMAKE_BINARY_DIR} --capture --output-file coverage.info --no-checksum
1027- COMMAND "${GENHTML_EXECUTABLE}" --prefix ${CMAKE_BINARY_DIR} --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
1028- )
1029- endif()
1030- endif()
1031-endif()
1032
1033=== modified file 'data/CMakeLists.txt'
1034--- data/CMakeLists.txt 2014-09-26 11:24:27 +0000
1035+++ data/CMakeLists.txt 2015-07-14 06:30:34 +0000
1036@@ -22,4 +22,3 @@
1037 "${CMAKE_CURRENT_BINARY_DIR}/thumbnailer"
1038 DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/apport/blacklist.d"
1039 )
1040-
1041
1042=== modified file 'data/com.canonical.Unity.Thumbnailer.gschema.xml'
1043--- data/com.canonical.Unity.Thumbnailer.gschema.xml 2014-09-16 13:00:17 +0000
1044+++ data/com.canonical.Unity.Thumbnailer.gschema.xml 2015-07-14 06:30:34 +0000
1045@@ -6,5 +6,72 @@
1046 <summary>API key for dash.ubuntu.com service</summary>
1047 <description>API key for dash.ubuntu.com service</description>
1048 </key>
1049+
1050+ <key type="i" name="full-size-cache-size">
1051+ <default>50</default>
1052+ <summary>Size of the full-size image cache in megabytes</summary>
1053+ <description>The full-size cache is used to store full-size extracted media artwork and downloaded album art.</description>
1054+ </key>
1055+
1056+ <key type="i" name="thumbnail-cache-size">
1057+ <default>100</default>
1058+ <summary>Size of the thumbnail image cache in megabytes</summary>
1059+ <description>The thumbnail image cache stores scaled thumbnail images.</description>
1060+ </key>
1061+
1062+ <key type="i" name="failure-cache-size">
1063+ <default>2</default>
1064+ <summary>Size of the failure cache in megabytes</summary>
1065+ <description>The failure cache records information about failed downloads or failed thumbnail extractions.</description>
1066+ </key>
1067+
1068+ <key type="i" name="max-thumbnail-size">
1069+ <default>1920</default>
1070+ <summary>Maximum size in pixels for a thumbnail</summary>
1071+ <description>
1072+ Requests for thumbnails larger than this will automatically reduce the thumbnail to max-thumbnail-size in the larger dimension. An exception are requests for local thumbnails with size 0x0, which are returned in their original size.
1073+ </description>
1074+ </key>
1075+
1076+ <key type="i" name="retry-not-found-hours">
1077+ <default>168</default>
1078+ <summary>Time to wait before re-trying for remote artwork that did not exist</summary>
1079+ <description>
1080+ If artwork cannot be retrieved because the remote server authoritavely confirmed that no artwork exists for an artist and album, this parameter defines how long the thumbnailer waits before trying to download the same image again. The default is 168 hours (one week).
1081+ </description>
1082+ </key>
1083+
1084+ <key type="i" name="retry-error-hours">
1085+ <default>2</default>
1086+ <summary>Time to wait before re-trying remote artwork that failed to download</summary>
1087+ <description>
1088+ If artwork cannot be retrieved from the remote server due to an unexpected error (such as the server not responding), this parameter defines how long the thumbnailer waits before trying to download the same image again. The default is two hours.
1089+ </description>
1090+ </key>
1091+
1092+ <key type="i" name="max-downloads">
1093+ <default>2</default>
1094+ <summary>Maximum number of concurrent downloads</summary>
1095+ <description>
1096+ This parameter sets the maximum number of concurrent downloads for remote artwork.
1097+ </description>
1098+ </key>
1099+
1100+ <key type="i" name="max-extractions">
1101+ <default>0</default>
1102+ <summary>Maximum number of concurrent image extractions</summary>
1103+ <description>
1104+ This parameter sets the maximum number of concurrent image extractions from local media files. The default value is zero, which sets the value according to the number of CPU cores.
1105+ </description>
1106+ </key>
1107+
1108+ <key type="i" name="extraction-timeout">
1109+ <default>10</default>
1110+ <summary>Maximum amount of time to wait for an image extraction or download (in seconds)</summary>
1111+ <description>
1112+ This parameter sets the amount of time (in seconds) to wait for a remote image download or
1113+ a thumbnail extraction before giving up.
1114+ </description>
1115+ </key>
1116 </schema>
1117 </schemalist>
1118
1119=== modified file 'debian/changelog'
1120--- debian/changelog 2015-03-12 08:38:44 +0000
1121+++ debian/changelog 2015-07-14 06:30:34 +0000
1122@@ -1,3 +1,52 @@
1123+thumbnailer (2.1-0ubuntu1) UNRELEASED; urgency=medium
1124+
1125+ [ James Henstridge ]
1126+ * Expose more settings for the thumbnailer daemon via GSettings.
1127+ * Change the security policy implementation to use aa_query_label()
1128+ for file access checks rather than relying on file descriptor
1129+ passing. This avoids the file descriptor exhaustion bugs with the
1130+ previous implementation. (LP: #1381713)
1131+
1132+ [ Michi Henning ]
1133+ * Add thumbnailer-admin tool, which can be used to check the status
1134+ of the cache and generate thumbnails via the command line.
1135+ * Add time stamps to log messages.
1136+ * Reduce the memory footprint of small caches, which in turn reduces
1137+ the footprint of thumbnailer-service.
1138+ * Don't implicitly compact the cache on service shutdown, as this
1139+ can take some time.
1140+ * Persist the cache stats over restarts of thumbnailer-service.
1141+ * Don't save JPEG thumbnails at quality=100, since the quality
1142+ improvement isn't justified by the extra storage.
1143+ * Don't retry downloads when we have a hit from the failure cache.
1144+ * Warn if an app requests an unsized thumbnail.
1145+
1146+ -- James Henstridge <james.henstridge@canonical.com> Mon, 22 Jun 2015 17:31:39 +0800
1147+
1148+thumbnailer (2.0+15.10.20150527-0ubuntu2) wily; urgency=medium
1149+
1150+ * Switch to unversioned Conflicts/Replaces on libthumbnailer0 to force
1151+ removal of the obsolete package on upgrade from the previous version.
1152+
1153+ -- Adam Conrad <adconrad@ubuntu.com> Wed, 17 Jun 2015 05:15:54 -0600
1154+
1155+thumbnailer (2.0+15.10.20150527-0ubuntu1) wily; urgency=medium
1156+
1157+ [ James Henstridge ]
1158+ * New upstream version with many changes:
1159+ - Switch to new cache implementation based on leveldb.
1160+ - Move local file thumbnailing to the central D-Bus daemon,
1161+ allowing for the cache to be shared between apps and its size
1162+ kept under control.
1163+ - The libthumbnailer library has been removed, since all clients
1164+ of the cache rely on the D-Bus interface now.
1165+ - The QML plugin now uses the QQuickAsyncImageProvider interface,
1166+ enabling multiple thumbnails to be loaded simultaneously.
1167+ - Improved test coverage.
1168+ * Remove the libthumbnailer0 and libthumbnailer-dev binary packages.
1169+
1170+ -- CI Train Bot <ci-train-bot@canonical.com> Wed, 27 May 2015 05:36:31 +0000
1171+
1172 thumbnailer (1.3+15.04.20150312-0ubuntu1) vivid; urgency=medium
1173
1174 [ Albert Astals Cid ]
1175
1176=== modified file 'debian/control'
1177--- debian/control 2014-09-25 07:23:54 +0000
1178+++ debian/control 2015-07-14 06:30:34 +0000
1179@@ -4,57 +4,43 @@
1180 Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>
1181 Standards-Version: 3.9.4
1182 Build-Depends: cmake,
1183+ cmake-extras (>= 0.4),
1184 debhelper (>= 9),
1185 gstreamer1.0-plugins-good,
1186+ libapparmor-dev,
1187+ libboost-filesystem-dev,
1188+ libboost-regex-dev,
1189 libexif-dev,
1190 libgdk-pixbuf2.0-dev,
1191 libgstreamer1.0-dev,
1192 libgstreamer-plugins-base1.0-dev,
1193 libgtest-dev,
1194- libsoup2.4-dev,
1195- libxml2-dev,
1196+ libleveldb-dev,
1197+ libqtdbustest1-dev,
1198+ libunity-api-dev,
1199+ python3-tornado,
1200+ qml-module-qtquick2,
1201+ qml-module-qttest,
1202 qt5-default,
1203 qtbase5-dev,
1204 qtbase5-dev-tools,
1205 qtdeclarative5-dev,
1206 shared-mime-info,
1207+ xvfb,
1208 Homepage: https://launchpad.net/thumbnailer
1209 # if you don't have have commit access to this branch but would like to upload
1210 # directly to Ubuntu, don't worry: your changes will be merged back into the
1211 # upstream branch
1212 Vcs-Bzr: lp:thumbnailer
1213
1214-Package: libthumbnailer0
1215-Architecture: any
1216-Multi-Arch: same
1217-Pre-Depends: ${misc:Pre-Depends},
1218-Depends: ${misc:Depends},
1219- ${shlibs:Depends},
1220-Description: generate thumbnails from files
1221- Thumbnailer is a shared library that generates
1222- thumbnail images for multiple file types such
1223- as video and audio files.
1224-
1225-Package: libthumbnailer-dev
1226-Architecture: any
1227-Multi-Arch: same
1228-Pre-Depends: ${misc:Pre-Depends},
1229-Depends: ${misc:Depends},
1230- ${shlibs:Depends},
1231- gstreamer1.0-plugins-base,
1232- gstreamer1.0-plugins-good,
1233- libthumbnailer0 (= ${binary:Version}),
1234-Description: development files for thumbnailer
1235- This package contains development files
1236- for the thumbnailer package.
1237-
1238 Package: thumbnailer-service
1239 Architecture: any
1240 Multi-Arch: foreign
1241 Pre-Depends: ${misc:Pre-Depends},
1242 Depends: ${misc:Depends},
1243 ${shlibs:Depends},
1244- libthumbnailer0 (= ${binary:Version}),
1245+Conflicts: libthumbnailer0
1246+Replaces: libthumbnailer0
1247 Description: D-Bus service for out of process thumbnailing
1248 This package provides a D-Bus service that can provide thumbnails on
1249 behalf of another process.
1250@@ -66,7 +52,6 @@
1251 Depends: ${misc:Depends},
1252 ${shlibs:Depends},
1253 thumbnailer-common (= ${binary:Version}),
1254- libthumbnailer0 (= ${binary:Version}),
1255 Provides: ubuntu-thumbnailer-impl,
1256 ubuntu-thumbnailer-impl-0,
1257 Recommends: thumbnailer-service (= ${binary:Version}),
1258
1259=== modified file 'debian/copyright'
1260--- debian/copyright 2013-09-30 15:55:07 +0000
1261+++ debian/copyright 2015-07-14 06:30:34 +0000
1262@@ -3,7 +3,27 @@
1263 Source: https://launchpad.net/thumbnailer
1264
1265 Files: *
1266-Copyright: 2013 Canonical ltd
1267+Copyright: 2015 Canonical Ltd.
1268+License: GPL-3
1269+ This program is free software: you can redistribute it and/or modify
1270+ it under the terms of the GNU General Public License version 3 as
1271+ published by the Free Software Foundation.
1272+ .
1273+ This program is distributed in the hope that it will be useful,
1274+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1275+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1276+ GNU General Public License for more details.
1277+ .
1278+ On Debian/Ubuntu systems, the full text of the GPL v3 can be found in
1279+ `/usr/share/common-licenses/GPL-3'
1280+
1281+Files: plugins/*
1282+ src/core/*
1283+ include/core/*
1284+ tests/core/* include/internal/gobj_memory.h
1285+ include/internal/safe_strerror.h
1286+ src/safe_strerror.cpp
1287+Copyright: 2015 Canonical ltd
1288 License: LGPL-3
1289 This program is free software: you can redistribute it and/or modify
1290 it under the terms of version 3 of the GNU Lesser General Public
1291@@ -12,7 +32,7 @@
1292 This program is distributed in the hope that it will be useful,
1293 but WITHOUT ANY WARRANTY; without even the implied warranty of
1294 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1295- GNU General Public License for more details.
1296+ GNU Lesser General Public License for more details.
1297 .
1298 On Debian systems, the full text of the GNU Lesser General Public
1299 License version 3 can be found in the file
1300
1301=== removed file 'debian/libthumbnailer-dev.install'
1302--- debian/libthumbnailer-dev.install 2013-09-25 12:45:32 +0000
1303+++ debian/libthumbnailer-dev.install 1970-01-01 00:00:00 +0000
1304@@ -1,3 +0,0 @@
1305-usr/include/*
1306-usr/lib/*/lib*.so
1307-usr/lib/*/pkgconfig/*
1308
1309=== removed file 'debian/libthumbnailer0.install'
1310--- debian/libthumbnailer0.install 2014-09-26 11:24:27 +0000
1311+++ debian/libthumbnailer0.install 1970-01-01 00:00:00 +0000
1312@@ -1,2 +0,0 @@
1313-usr/lib/*/libthumb*.so.*
1314-usr/lib/*/thumbnailer/vs-thumb
1315
1316=== removed file 'debian/libthumbnailer0.symbols'
1317--- debian/libthumbnailer0.symbols 2014-08-11 14:20:31 +0000
1318+++ debian/libthumbnailer0.symbols 1970-01-01 00:00:00 +0000
1319@@ -1,7 +0,0 @@
1320-libthumbnailer.so.0 libthumbnailer0 #MINVER#
1321- (c++)"Thumbnailer::get_thumbnail(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ThumbnailSize)@Base" 1.0
1322- (c++)"Thumbnailer::get_thumbnail(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ThumbnailSize, ThumbnailPolicy)@Base" 1.0
1323- (c++)"Thumbnailer::get_album_art(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ThumbnailSize, ThumbnailPolicy)@Base" 1.0
1324- (c++)"Thumbnailer::Thumbnailer()@Base" 1.0
1325- (c++)"Thumbnailer::~Thumbnailer()@Base" 1.0
1326- (c++)"Thumbnailer::get_artist_art(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ThumbnailSize, ThumbnailPolicy)@Base" 1.1+14.10.20140811
1327
1328=== modified file 'debian/rules'
1329--- debian/rules 2014-09-25 08:54:10 +0000
1330+++ debian/rules 2015-07-14 06:30:34 +0000
1331@@ -15,3 +15,6 @@
1332 override_dh_auto_configure:
1333 dh_auto_configure -- -DCMAKE_INSTALL_SYSCONFDIR=/etc
1334
1335+# Tests are not written to be run in parallel.
1336+override_dh_auto_test:
1337+ dh_auto_test --max-parallel=1 -- ARGS="--verbose"
1338
1339=== modified file 'debian/thumbnailer-service.install'
1340--- debian/thumbnailer-service.install 2014-09-16 12:12:21 +0000
1341+++ debian/thumbnailer-service.install 2015-07-14 06:30:34 +0000
1342@@ -1,3 +1,5 @@
1343+usr/bin/thumbnailer-admin
1344 usr/lib/*/thumbnailer/thumbnailer-service
1345+usr/lib/*/thumbnailer/vs-thumb
1346 usr/share/dbus-1/services/com.canonical.Thumbnailer.service
1347 usr/share/glib-2.0/schemas/*
1348
1349=== modified file 'include/CMakeLists.txt'
1350--- include/CMakeLists.txt 2013-10-02 09:43:16 +0000
1351+++ include/CMakeLists.txt 2015-07-14 06:30:34 +0000
1352@@ -1,12 +1,1 @@
1353 add_subdirectory(internal)
1354-
1355-install(FILES thumbnailer.h DESTINATION include)
1356-
1357-# Build and install a pkg-config file
1358-set(prefix ${CMAKE_INSTALL_PREFIX})
1359-set(exec_prefix ${prefix}/bin)
1360-set(libdir ${prefix}/${LIBDIR})
1361-set(includedir ${prefix}/include)
1362-set(pkg-name "lib${COL_LIB_BASENAME}")
1363-configure_file(thumbnailer.pc.in thumbnailer.pc @ONLY)
1364-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/thumbnailer.pc DESTINATION ${LIBDIR}/pkgconfig)
1365
1366=== added directory 'include/core'
1367=== added file 'include/core/CMakeLists.txt'
1368=== added file 'include/core/cache_codec.h'
1369--- include/core/cache_codec.h 1970-01-01 00:00:00 +0000
1370+++ include/core/cache_codec.h 2015-07-14 06:30:34 +0000
1371@@ -0,0 +1,50 @@
1372+/*
1373+ * Copyright (C) 2015 Canonical Ltd.
1374+ *
1375+ * This program is free software: you can redistribute it and/or modify
1376+ * it under the terms of the GNU Lesser General Public License version 3 as
1377+ * published by the Free Software Foundation.
1378+ *
1379+ * This program is distributed in the hope that it will be useful,
1380+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1381+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1382+ * GNU Lesser General Public License for more details.
1383+ *
1384+ * You should have received a copy of the GNU Lesser General Public License
1385+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1386+ *
1387+ * Authored by: Michi Henning <michi.henning@canonical.com>
1388+ */
1389+
1390+#pragma once
1391+
1392+#include <string>
1393+
1394+namespace core
1395+{
1396+
1397+/**
1398+Traits for serialization and deserialization of cache custom types.
1399+To use custom types, specialize this template
1400+for each custom type (other than string) in the `core` namespace.
1401+
1402+\warning Do _not_ specialize this struct for `std::string`!
1403+Doing so has no effect.
1404+
1405+\see PersistentCache
1406+*/
1407+
1408+template <typename T>
1409+struct CacheCodec
1410+{
1411+ /**
1412+ \brief Converts a value of custom type T into a string.
1413+ */
1414+ static std::string encode(T const& value);
1415+ /**
1416+ \brief Converts a string into a value of custom type T.
1417+ */
1418+ static T decode(std::string const& s);
1419+};
1420+
1421+} // namespace core
1422
1423=== added file 'include/core/cache_discard_policy.h'
1424--- include/core/cache_discard_policy.h 1970-01-01 00:00:00 +0000
1425+++ include/core/cache_discard_policy.h 2015-07-14 06:30:34 +0000
1426@@ -0,0 +1,41 @@
1427+/*
1428+ * Copyright (C) 2015 Canonical Ltd.
1429+ *
1430+ * This program is free software: you can redistribute it and/or modify
1431+ * it under the terms of the GNU Lesser General Public License version 3 as
1432+ * published by the Free Software Foundation.
1433+ *
1434+ * This program is distributed in the hope that it will be useful,
1435+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1436+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1437+ * GNU Lesser General Public License for more details.
1438+ *
1439+ * You should have received a copy of the GNU Lesser General Public License
1440+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1441+ *
1442+ * Authored by: Michi Henning <michi.henning@canonical.com>
1443+ */
1444+
1445+#pragma once
1446+
1447+namespace core
1448+{
1449+
1450+/**
1451+\brief Indicates the discard policy to make room for entries when the cache is full.
1452+
1453+Once the cache is full and another entry is added,
1454+`lru_ttl` unconditionally deletes all entries that have expired and then,
1455+if deleting these entries did not create sufficient free space, deletes entries
1456+in least-recently-used order until enough space is available.
1457+
1458+If the discard policy is set to `lru_only`, entries do not maintain an expiry time and
1459+are therefore discarded strictly in LRU order.
1460+*/
1461+enum class CacheDiscardPolicy
1462+{
1463+ lru_ttl, ///< Evict expired entries first, followed by eviction in LRU order
1464+ lru_only ///< Evict in LRU order
1465+};
1466+
1467+} // namespace core
1468
1469=== added file 'include/core/cache_events.h'
1470--- include/core/cache_events.h 1970-01-01 00:00:00 +0000
1471+++ include/core/cache_events.h 2015-07-14 06:30:34 +0000
1472@@ -0,0 +1,103 @@
1473+/*
1474+ * Copyright (C) 2015 Canonical Ltd.
1475+ *
1476+ * This program is free software: you can redistribute it and/or modify
1477+ * it under the terms of the GNU Lesser General Public License version 3 as
1478+ * published by the Free Software Foundation.
1479+ *
1480+ * This program is distributed in the hope that it will be useful,
1481+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1482+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1483+ * GNU Lesser General Public License for more details.
1484+ *
1485+ * You should have received a copy of the GNU Lesser General Public License
1486+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1487+ *
1488+ * Authored by: Michi Henning <michi.henning@canonical.com>
1489+ */
1490+
1491+#pragma once
1492+
1493+#include <cstdint>
1494+#include <type_traits>
1495+
1496+/**
1497+\brief Top-level namespace for core functionality.
1498+*/
1499+
1500+namespace core
1501+{
1502+
1503+/**
1504+\brief Event types that can be monitored.
1505+*/
1506+
1507+// Note: Any change here must have a corresponding change to
1508+// CacheEventIndex in core/internal/cache_event_indexes.h!
1509+
1510+enum class CacheEvent : uint32_t
1511+{
1512+ get = 1 << 0, ///< An entry was returned by a call to `get()`, `get_or_put()`, `take()`, or `take_data()`.
1513+ put = 1 << 1, ///< An entry was added by a call to `put()` or `get_or_put()`.
1514+ invalidate = 1 << 2, ///< An entry was removed by a call to `invalidate()`, `take()`, or `take_data()`.
1515+ touch = 1 << 3, ///< An entry was refreshed by a call to `touch()`.
1516+ miss = 1 << 4, ///< A call to `get()`, `get_or_put()`, `take()`, or `take_data()` failed to return an entry.
1517+ evict_ttl = 1 << 5, ///< An expired entry was evicted due to a call to `put()`,
1518+ ///< `get_or_put()`, `trim_to()`, or `resize()`.
1519+ evict_lru = 1 << 6, ///< The oldest entry was evicted due to a call to `put()`,
1520+ ///< `get_or_put()`, `trim_to()`, or `resize()`.
1521+ END_ = 1 << 7 ///< End marker
1522+};
1523+
1524+/**
1525+\brief Returns the bitwise OR of two event types.
1526+*/
1527+inline CacheEvent operator|(CacheEvent left, CacheEvent right)
1528+{
1529+ auto l = std::underlying_type<CacheEvent>::type(left);
1530+ auto r = std::underlying_type<CacheEvent>::type(right);
1531+ return CacheEvent(l | r);
1532+}
1533+
1534+/**
1535+\brief Assigns the bitwise OR of `left` and `right` to `left`.
1536+*/
1537+inline CacheEvent& operator|=(CacheEvent& left, CacheEvent right)
1538+{
1539+ return left = left | right;
1540+}
1541+
1542+/**
1543+\brief Returns the bitwise AND of two event types.
1544+*/
1545+inline CacheEvent operator&(CacheEvent left, CacheEvent right)
1546+{
1547+ auto l = std::underlying_type<CacheEvent>::type(left);
1548+ auto r = std::underlying_type<CacheEvent>::type(right);
1549+ return CacheEvent(l & r);
1550+}
1551+
1552+/**
1553+\brief Assigns the bitwise AND of `left` and `right` to `left`.
1554+*/
1555+inline CacheEvent& operator&=(CacheEvent& left, CacheEvent right)
1556+{
1557+ return left = left & right;
1558+}
1559+
1560+/**
1561+\brief Returns the bitwise NOT of `ev`. Unused bits are set to zero.
1562+*/
1563+inline CacheEvent operator~(CacheEvent ev)
1564+{
1565+ auto mask = std::underlying_type<CacheEvent>::type(CacheEvent::END_) - 1;
1566+ auto event = std::underlying_type<CacheEvent>::type(ev);
1567+ return CacheEvent(~event & mask);
1568+}
1569+
1570+/**
1571+\brief Convenience definition for all event types.
1572+*/
1573+static constexpr auto AllCacheEvents = CacheEvent(std::underlying_type<CacheEvent>::type(CacheEvent::END_) - 1);
1574+
1575+} // namespace core
1576
1577=== added directory 'include/core/internal'
1578=== added file 'include/core/internal/cache_event_indexes.h'
1579--- include/core/internal/cache_event_indexes.h 1970-01-01 00:00:00 +0000
1580+++ include/core/internal/cache_event_indexes.h 2015-07-14 06:30:34 +0000
1581@@ -0,0 +1,46 @@
1582+/*
1583+ * Copyright (C) 2015 Canonical Ltd.
1584+ *
1585+ * This program is free software: you can redistribute it and/or modify
1586+ * it under the terms of the GNU Lesser General Public License version 3 as
1587+ * published by the Free Software Foundation.
1588+ *
1589+ * This program is distributed in the hope that it will be useful,
1590+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1591+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1592+ * GNU Lesser General Public License for more details.
1593+ *
1594+ * You should have received a copy of the GNU Lesser General Public License
1595+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1596+ *
1597+ * Authored by: Michi Henning <michi.henning@canonical.com>
1598+ */
1599+
1600+#pragma once
1601+
1602+#include <cstdint>
1603+
1604+namespace core
1605+{
1606+
1607+namespace internal
1608+{
1609+
1610+// Note: Any change here must have a corresponding change to
1611+// CacheEvent in core/cache_events.h!
1612+
1613+enum class CacheEventIndex : uint32_t
1614+{
1615+ get = 0,
1616+ put = 1,
1617+ invalidate = 2,
1618+ touch = 3,
1619+ miss = 4,
1620+ evict_ttl = 5,
1621+ evict_lru = 6,
1622+ END_ = 7
1623+};
1624+
1625+} // namespace internal
1626+
1627+} // namespace core
1628
1629=== added file 'include/core/internal/persistent_string_cache_impl.h'
1630--- include/core/internal/persistent_string_cache_impl.h 1970-01-01 00:00:00 +0000
1631+++ include/core/internal/persistent_string_cache_impl.h 2015-07-14 06:30:34 +0000
1632@@ -0,0 +1,191 @@
1633+/*
1634+ * Copyright (C) 2015 Canonical Ltd.
1635+ *
1636+ * This program is free software: you can redistribute it and/or modify
1637+ * it under the terms of the GNU Lesser General Public License version 3 as
1638+ * published by the Free Software Foundation.
1639+ *
1640+ * This program is distributed in the hope that it will be useful,
1641+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1642+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1643+ * GNU Lesser General Public License for more details.
1644+ *
1645+ * You should have received a copy of the GNU Lesser General Public License
1646+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1647+ *
1648+ * Authored by: Michi Henning <michi.henning@canonical.com>
1649+ */
1650+
1651+#pragma once
1652+
1653+#include <core/internal/cache_event_indexes.h>
1654+#include <core/persistent_string_cache.h>
1655+
1656+#include <leveldb/db.h>
1657+
1658+#include <mutex>
1659+#include <sstream>
1660+
1661+namespace core
1662+{
1663+
1664+namespace internal
1665+{
1666+
1667+class PersistentStringCacheStats;
1668+
1669+class PersistentStringCacheImpl
1670+{
1671+public:
1672+ PersistentStringCacheImpl(std::string const& cache_path,
1673+ int64_t max_size_in_bytes,
1674+ core::CacheDiscardPolicy policy,
1675+ PersistentStringCache* pimpl = nullptr);
1676+ PersistentStringCacheImpl(std::string const& cache_path, PersistentStringCache* pimpl = nullptr);
1677+
1678+ PersistentStringCacheImpl(PersistentStringCacheImpl const&) = delete;
1679+ PersistentStringCacheImpl& operator=(PersistentStringCacheImpl const&) = delete;
1680+
1681+ PersistentStringCacheImpl(PersistentStringCacheImpl&&) = delete;
1682+ PersistentStringCacheImpl& operator=(PersistentStringCacheImpl&&) = delete;
1683+
1684+ ~PersistentStringCacheImpl();
1685+
1686+ bool get(std::string const& key, std::string& value) const;
1687+ bool get(std::string const& key, std::string& value, std::string* metadata) const;
1688+ bool get_metadata(std::string const& key, std::string& metadata) const;
1689+ bool contains_key(std::string const& key) const;
1690+ int64_t size() const noexcept;
1691+ int64_t size_in_bytes() const noexcept;
1692+ int64_t max_size_in_bytes() const noexcept;
1693+ int64_t disk_size_in_bytes() const;
1694+ CacheDiscardPolicy discard_policy() const noexcept;
1695+ core::PersistentCacheStats stats() const;
1696+
1697+ bool put(std::string const& key,
1698+ std::string const& value,
1699+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
1700+ bool put(std::string const& key,
1701+ char const* value,
1702+ int64_t size,
1703+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
1704+ bool put(std::string const& key,
1705+ std::string const& value,
1706+ std::string const* metadata,
1707+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
1708+ bool put(std::string const& key,
1709+ char const* value_data,
1710+ int64_t value_size,
1711+ char const* metadata_data,
1712+ int64_t metadata_size,
1713+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
1714+ bool get_or_put(std::string const& key, std::string& value, PersistentStringCache::Loader load_func);
1715+ bool get_or_put(std::string const& key,
1716+ std::string& value,
1717+ std::string* metadata,
1718+ PersistentStringCache::Loader load_func);
1719+ bool put_metadata(std::string const& key, std::string const& metadata);
1720+ bool put_metadata(std::string const& key, char const* metadata, int64_t metadata_size);
1721+ bool take(std::string const& key, std::string& value);
1722+ bool take(std::string const& key, std::string& value, std::string* metadata);
1723+ bool invalidate(std::string const& key);
1724+ void invalidate(std::vector<std::string> const& keys);
1725+ template<typename It>
1726+ void invalidate(It begin, It end);
1727+ void invalidate(std::initializer_list<std::string> const& keys);
1728+ void invalidate();
1729+ bool touch(
1730+ std::string const& key,
1731+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
1732+ void clear_stats() noexcept;
1733+ void resize(int64_t size_in_bytes);
1734+ void trim_to(int64_t used_size_in_bytes);
1735+ void compact();
1736+ void set_handler(CacheEvent events, PersistentStringCache::EventCallback cb);
1737+
1738+private:
1739+ // Simple struct to serialize/deserialize a data tuple.
1740+ // For the stringified representation, fields are separated
1741+ // by a space.
1742+
1743+ struct DataTuple
1744+ {
1745+ int64_t atime; // Last access time, msec since the epoch
1746+ int64_t etime; // Expiry time, msec since the epoch
1747+ int64_t size; // Size in bytes
1748+
1749+ DataTuple(int64_t at, int64_t et, int64_t s) noexcept
1750+ : atime(at)
1751+ , etime(et)
1752+ , size(s)
1753+ {
1754+ }
1755+
1756+ DataTuple() noexcept
1757+ : DataTuple(0, 0, 0)
1758+ {
1759+ }
1760+
1761+ DataTuple(std::string const& s) noexcept
1762+ {
1763+ std::istringstream is(s);
1764+ is >> atime >> etime >> size;
1765+ assert(!is.bad());
1766+ }
1767+
1768+ DataTuple(DataTuple const&) = default;
1769+ DataTuple(DataTuple&&) = default;
1770+
1771+ DataTuple& operator=(DataTuple const&) = default;
1772+ DataTuple& operator=(DataTuple&&) = default;
1773+
1774+ std::string to_string() const
1775+ {
1776+ std::ostringstream os;
1777+ os << atime << " " << etime << " " << size;
1778+ return os.str();
1779+ }
1780+ };
1781+
1782+ void init_stats();
1783+ void init_db(leveldb::Options options);
1784+ bool cache_is_new() const;
1785+ void write_version();
1786+ void check_version();
1787+ void read_settings();
1788+ void write_settings();
1789+ void read_stats();
1790+ void write_stats();
1791+ bool read_dirty_flag() const;
1792+ void write_dirty_flag(bool is_dirty);
1793+ DataTuple get_data(std::string const& key, bool& found) const;
1794+ bool get_value_and_metadata(std::string const& key,
1795+ DataTuple& data,
1796+ std::string& value,
1797+ std::string* metadata) const;
1798+ void batch_delete(std::string const& key, DataTuple const& data, leveldb::WriteBatch& batch);
1799+ void delete_entry(std::string const& key, DataTuple const& data);
1800+ void delete_at_least(int64_t bytes_needed, std::string const& skip_key = "");
1801+ void call_handler(std::string const& key, core::internal::CacheEventIndex event) const;
1802+
1803+ std::string make_message(leveldb::Status const& s, std::string const& msg) const;
1804+ std::string make_message(std::string const& msg) const;
1805+ void throw_if_error(leveldb::Status const& s, std::string const& msg) const;
1806+ void throw_logic_error(std::string const& msg) const;
1807+ void throw_invalid_argument(std::string const& msg) const;
1808+ void throw_corrupt_error(std::string const& msg) const;
1809+
1810+ PersistentStringCache* pimpl_; // Back-pointer to owning pimpl.
1811+ std::unique_ptr<leveldb::Cache> block_cache_; // Must be defined *before* db_!
1812+ std::unique_ptr<leveldb::DB> db_;
1813+ std::shared_ptr<PersistentStringCacheStats> stats_;
1814+
1815+ std::array<PersistentStringCache::EventCallback, static_cast<unsigned>(CacheEventIndex::END_)>
1816+ handlers_;
1817+
1818+ mutable std::recursive_mutex mutex_;
1819+};
1820+
1821+} // namespace internal
1822+
1823+} // namespace core
1824
1825=== added file 'include/core/internal/persistent_string_cache_stats.h'
1826--- include/core/internal/persistent_string_cache_stats.h 1970-01-01 00:00:00 +0000
1827+++ include/core/internal/persistent_string_cache_stats.h 2015-07-14 06:30:34 +0000
1828@@ -0,0 +1,237 @@
1829+/*
1830+ * Copyright (C) 2015 Canonical Ltd.
1831+ *
1832+ * This program is free software: you can redistribute it and/or modify
1833+ * it under the terms of the GNU Lesser General Public License version 3 as
1834+ * published by the Free Software Foundation.
1835+ *
1836+ * This program is distributed in the hope that it will be useful,
1837+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1838+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1839+ * GNU Lesser General Public License for more details.
1840+ *
1841+ * You should have received a copy of the GNU Lesser General Public License
1842+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1843+ *
1844+ * Authored by: Michi Henning <michi.henning@canonical.com>
1845+ */
1846+
1847+#pragma once
1848+
1849+#include <core/cache_discard_policy.h>
1850+#include <core/persistent_cache_stats.h>
1851+
1852+#include <cassert>
1853+#include <cmath>
1854+#include <cstring>
1855+#include <sstream>
1856+
1857+namespace core
1858+{
1859+
1860+namespace internal
1861+{
1862+
1863+// Simple stats class to keep track of accesses.
1864+
1865+class PersistentStringCacheStats
1866+{
1867+public:
1868+ PersistentStringCacheStats() noexcept
1869+ : policy_(CacheDiscardPolicy::lru_only)
1870+ , max_cache_size_(0)
1871+ , num_entries_(0)
1872+ , cache_size_(0)
1873+ , state_(Initialized)
1874+ {
1875+ clear();
1876+ hist_.resize(PersistentCacheStats::NUM_BINS, 0);
1877+ }
1878+
1879+ PersistentStringCacheStats(PersistentStringCacheStats const&) = default;
1880+ PersistentStringCacheStats(PersistentStringCacheStats&&) = default;
1881+ PersistentStringCacheStats& operator=(PersistentStringCacheStats const&) = default;
1882+ PersistentStringCacheStats& operator=(PersistentStringCacheStats&&) = default;
1883+
1884+ std::string cache_path_; // Immutable
1885+ core::CacheDiscardPolicy policy_; // Immutable
1886+ int64_t max_cache_size_;
1887+
1888+ int64_t num_entries_;
1889+ int64_t cache_size_;
1890+ PersistentCacheStats::Histogram hist_;
1891+
1892+ // Values below are reset by a call to clear().
1893+ int64_t hits_;
1894+ int64_t misses_;
1895+ int64_t hits_since_last_miss_;
1896+ int64_t misses_since_last_hit_;
1897+ int64_t longest_hit_run_;
1898+ int64_t longest_miss_run_;
1899+ int64_t ttl_evictions_;
1900+ int64_t lru_evictions_;
1901+ std::chrono::system_clock::time_point most_recent_hit_time_;
1902+ std::chrono::system_clock::time_point most_recent_miss_time_;
1903+ std::chrono::system_clock::time_point longest_hit_run_time_;
1904+ std::chrono::system_clock::time_point longest_miss_run_time_;
1905+
1906+ enum State
1907+ {
1908+ Initialized,
1909+ LastAccessWasHit,
1910+ LastAccessWasMiss
1911+ };
1912+ State state_;
1913+
1914+ void inc_hits() noexcept
1915+ {
1916+ ++hits_since_last_miss_;
1917+ ++hits_;
1918+ most_recent_hit_time_ = std::chrono::system_clock::now();
1919+ misses_since_last_hit_ = 0;
1920+ if (state_ != LastAccessWasHit)
1921+ {
1922+ state_ = LastAccessWasHit;
1923+ misses_since_last_hit_ = 0;
1924+ }
1925+ if (state_ != LastAccessWasMiss && hits_since_last_miss_ > longest_hit_run_)
1926+ {
1927+ longest_hit_run_ = hits_since_last_miss_;
1928+ longest_hit_run_time_ = most_recent_hit_time_;
1929+ }
1930+ }
1931+
1932+ void inc_misses() noexcept
1933+ {
1934+ ++misses_since_last_hit_;
1935+ ++misses_;
1936+ most_recent_miss_time_ = std::chrono::system_clock::now();
1937+ hits_since_last_miss_ = 0;
1938+ if (state_ != LastAccessWasMiss)
1939+ {
1940+ state_ = LastAccessWasMiss;
1941+ hits_since_last_miss_ = 0;
1942+ }
1943+ if (state_ != LastAccessWasHit && misses_since_last_hit_ > longest_miss_run_)
1944+ {
1945+ longest_miss_run_ = misses_since_last_hit_;
1946+ longest_miss_run_time_ = most_recent_miss_time_;
1947+ }
1948+ }
1949+
1950+ void hist_decrement(int64_t size) noexcept
1951+ {
1952+ assert(size > 0);
1953+ --hist_[size_to_index(size)];
1954+ }
1955+
1956+ void hist_increment(int64_t size) noexcept
1957+ {
1958+ assert(size > 0);
1959+ ++hist_[size_to_index(size)];
1960+ }
1961+
1962+ void hist_clear() noexcept
1963+ {
1964+ memset(&hist_[0], 0, hist_.size() * sizeof(PersistentCacheStats::Histogram::value_type));
1965+ }
1966+
1967+ void clear() noexcept
1968+ {
1969+ hits_ = 0;
1970+ misses_ = 0;
1971+ hits_since_last_miss_ = 0;
1972+ misses_since_last_hit_ = 0;
1973+ longest_hit_run_ = 0;
1974+ longest_miss_run_ = 0;
1975+ ttl_evictions_ = 0;
1976+ lru_evictions_ = 0;
1977+ most_recent_hit_time_ = std::chrono::system_clock::time_point();
1978+ most_recent_miss_time_ = std::chrono::system_clock::time_point();
1979+ longest_hit_run_time_ = std::chrono::system_clock::time_point();
1980+ longest_miss_run_time_ = std::chrono::system_clock::time_point();
1981+ }
1982+
1983+ // Serialize the stats.
1984+
1985+ std::string serialize() const
1986+ {
1987+ using namespace std;
1988+ using namespace std::chrono;
1989+
1990+ ostringstream os;
1991+ os << num_entries_ << " "
1992+ << cache_size_ << " "
1993+ << hits_ << " "
1994+ << misses_ << " "
1995+ << hits_since_last_miss_ << " "
1996+ << misses_since_last_hit_ << " "
1997+ << longest_hit_run_ << " "
1998+ << longest_miss_run_ << " "
1999+ << ttl_evictions_ << " "
2000+ << lru_evictions_ << " "
2001+ << duration_cast<milliseconds>(most_recent_hit_time_.time_since_epoch()).count() << " "
2002+ << duration_cast<milliseconds>(most_recent_miss_time_.time_since_epoch()).count() << " "
2003+ << duration_cast<milliseconds>(longest_hit_run_time_.time_since_epoch()).count() << " "
2004+ << duration_cast<milliseconds>(longest_miss_run_time_.time_since_epoch()).count();
2005+ for (auto d : hist_)
2006+ {
2007+ os << " " << d;
2008+ }
2009+ return os.str();
2010+ }
2011+
2012+ // De-serialize the stats.
2013+
2014+ void deserialize(const std::string& s) noexcept
2015+ {
2016+ using namespace std;
2017+ using namespace std::chrono;
2018+
2019+ istringstream is(s);
2020+ int64_t mrht;
2021+ int64_t mrmt;
2022+ int64_t lhrt;
2023+ int64_t lmrt;
2024+ is >> num_entries_
2025+ >> cache_size_
2026+ >> hits_
2027+ >> misses_
2028+ >> hits_since_last_miss_
2029+ >> misses_since_last_hit_
2030+ >> longest_hit_run_
2031+ >> longest_miss_run_
2032+ >> ttl_evictions_
2033+ >> lru_evictions_
2034+ >> mrht
2035+ >> mrmt
2036+ >> lhrt
2037+ >> lmrt;
2038+ for (unsigned i = 0; i < PersistentCacheStats::NUM_BINS; ++i)
2039+ {
2040+ is >> hist_[i];
2041+ }
2042+ assert(!is.bad());
2043+ most_recent_hit_time_ = system_clock::time_point(milliseconds(mrht));
2044+ most_recent_miss_time_ = system_clock::time_point(milliseconds(mrmt));
2045+ longest_hit_run_time_ = system_clock::time_point(milliseconds(lhrt));
2046+ longest_miss_run_time_ = system_clock::time_point(milliseconds(lmrt));
2047+ }
2048+
2049+private:
2050+ unsigned size_to_index(int64_t size) const noexcept
2051+ {
2052+ using namespace std;
2053+ assert(size > 0);
2054+ unsigned log = floor(log10(size)); // 0..9 = 0, 10..99 = 1, 100..199 = 2, etc.
2055+ unsigned exp = pow(10, log); // 0..9 = 1, 10..99 = 10, 100..199 = 100, etc.
2056+ unsigned div = size / exp; // Extracts first decimal digit of size.
2057+ int index = log * 10 + div - log - 1; // Partition each power of 10 into 9 bins.
2058+ index -= 8; // Sizes < 10 all go into bin 0;
2059+ return index < 0 ? 0 : (index > int(hist_.size()) - 1 ? hist_.size() - 1 : index);
2060+ }
2061+};
2062+
2063+} // namespace internal
2064+
2065+} // namespace core
2066
2067=== added file 'include/core/optional.h'
2068--- include/core/optional.h 1970-01-01 00:00:00 +0000
2069+++ include/core/optional.h 2015-07-14 06:30:34 +0000
2070@@ -0,0 +1,35 @@
2071+/*
2072+ * Copyright (C) 2015 Canonical Ltd.
2073+ *
2074+ * This program is free software: you can redistribute it and/or modify
2075+ * it under the terms of the GNU Lesser General Public License version 3 as
2076+ * published by the Free Software Foundation.
2077+ *
2078+ * This program is distributed in the hope that it will be useful,
2079+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2080+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2081+ * GNU Lesser General Public License for more details.
2082+ *
2083+ * You should have received a copy of the GNU Lesser General Public License
2084+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2085+ *
2086+ * Authored by: Michi Henning <michi.henning@canonical.com>
2087+ */
2088+
2089+#pragma once
2090+
2091+#include <boost/optional.hpp>
2092+
2093+namespace core
2094+{
2095+
2096+/**
2097+\brief Convenience typedef for nullable values.
2098+
2099+\note You should use `core::Optional` in preference to `boost::optional`
2100+in your code. This will ease an eventual transition to `std::optional`.
2101+*/
2102+template <typename T>
2103+using Optional = boost::optional<T>;
2104+
2105+} // namespace core
2106
2107=== added file 'include/core/persistent_cache.h'
2108--- include/core/persistent_cache.h 1970-01-01 00:00:00 +0000
2109+++ include/core/persistent_cache.h 2015-07-14 06:30:34 +0000
2110@@ -0,0 +1,3104 @@
2111+/*
2112+ * Copyright (C) 2015 Canonical Ltd.
2113+ *
2114+ * This program is free software: you can redistribute it and/or modify
2115+ * it under the terms of the GNU Lesser General Public License version 3 as
2116+ * published by the Free Software Foundation.
2117+ *
2118+ * This program is distributed in the hope that it will be useful,
2119+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2120+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2121+ * GNU Lesser General Public License for more details.
2122+ *
2123+ * You should have received a copy of the GNU Lesser General Public License
2124+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2125+ *
2126+ * Authored by: Michi Henning <michi.henning@canonical.com>
2127+ */
2128+
2129+#pragma once
2130+
2131+#include <core/cache_codec.h>
2132+#include <core/persistent_string_cache.h>
2133+
2134+namespace core
2135+{
2136+
2137+/**
2138+\brief A persistent cache of key-value pairs and metadata of user-defined type.
2139+
2140+`K`, `V`, and `M` are the key type, value type, and metadata type, respectively.
2141+
2142+\note This template is a simple type adapter that forwards to
2143+core::PersistentStringCache. See the documentation there for details
2144+on cache operations and semantics.
2145+
2146+In order to use the cache with custom types (other than `std::string`),
2147+you must provide methods to encode the type to `string`, and decode
2148+from `string` back to the type.
2149+
2150+For example, suppose we have the following structure that we want to use
2151+as the key type of the cache:
2152+
2153+\code{.cpp}
2154+struct Person
2155+{
2156+ string name;
2157+ int age;
2158+};
2159+\endcode
2160+
2161+In order to use the cache with the `Person` struct as the key, you must specialize
2162+the CacheCodec struct in namespace `core`:
2163+
2164+\code{.cpp}
2165+namespace core // Specializations must be placed into namespace core.
2166+{
2167+
2168+template <>
2169+string CacheCodec<Person>::encode(Person const& p)
2170+{
2171+ ostringstream s;
2172+ s << p.age << ' ' << p.name;
2173+ return s.str();
2174+}
2175+
2176+template <>
2177+Person CacheCodec<Person>::decode(string const& str)
2178+{
2179+ istringstream s;
2180+ Person p;
2181+ s >> p.age >> p.name;
2182+ return p;
2183+}
2184+
2185+} // namespace core
2186+\endcode
2187+
2188+For this example, it is convenient to stream the age first because this
2189+guarantees that `decode()` will work correctly even if the name contains
2190+a space. The order in which you stream the fields does not matter, only that
2191+(for custom _key_ types) the string representation of each value is unique.
2192+
2193+With these two methods defined, we can now use the cache with `Person` instances
2194+as the key. For example:
2195+
2196+\code{.cpp}
2197+// Custom cache using Person as the key, and string as the value and metadata.
2198+using PersonCache = core::PersistentCache<Person, string>;
2199+
2200+auto c = PersonCache::open("my_cache", 1024 * 1024 * 1024, CacheDiscardPolicy::LRU_only);
2201+
2202+Person bjarne{"Bjarne Stroustrup", 65};
2203+c->put(bjarne, "C++ inventor");
2204+auto value = c->get(bjarne);
2205+if (value)
2206+{
2207+ cout << bjarne.name << ": " << *value << endl;
2208+}
2209+Person person{"no such person", 0};
2210+value = c->get(person);
2211+assert(!value);
2212+\endcode
2213+
2214+Running this code produces the output:
2215+
2216+\code
2217+Bjarne Stroustrup: C++ inventor
2218+\endcode
2219+
2220+You can use a custom type for the cache's value and metadata as well by simply providing
2221+CacheCodec specializations as needed.
2222+
2223+\see core::CacheCodec
2224+\see core::PersistentStringCache
2225+*/
2226+
2227+template <typename K, typename V, typename M = std::string>
2228+class PersistentCache
2229+{
2230+public:
2231+ /**
2232+ Convenience typedef for the return type of open().
2233+ */
2234+ typedef std::unique_ptr<PersistentCache<K, V, M>> UPtr;
2235+
2236+ /**
2237+ \brief Simple pair of value and metadata.
2238+ */
2239+ struct Data
2240+ {
2241+ /**
2242+ \brief Stores the value of an entry.
2243+ */
2244+ V value;
2245+
2246+ /**
2247+ \brief Stores the metadata of an entry. If no metadata exists for an entry,
2248+ `metadata` is returned as the empty string when it is retrieved.
2249+ */
2250+ M metadata;
2251+ };
2252+
2253+ /** @name Typedefs for nullable keys, values, and metadata.
2254+ */
2255+
2256+ //{@
2257+
2258+ /**
2259+ \brief Convenience typedefs for returning nullable values.
2260+
2261+ \note You should use `OptionalKey`, `OptionalValue`, and `OptionalMetadata` in
2262+ your code in preference to `boost::optional`. This will ease an eventual
2263+ transition to `std::optional`.
2264+ */
2265+ typedef Optional<K> OptionalKey;
2266+ typedef Optional<V> OptionalValue;
2267+ typedef Optional<M> OptionalMetadata;
2268+ typedef Optional<Data> OptionalData;
2269+
2270+ //@}
2271+
2272+ /** @name Copy and Assignment
2273+ */
2274+
2275+ //{@
2276+ PersistentCache(PersistentCache const&) = delete;
2277+ PersistentCache& operator=(PersistentCache const&) = delete;
2278+
2279+ PersistentCache(PersistentCache&&) = default;
2280+ PersistentCache& operator=(PersistentCache&&) = default;
2281+ //@}
2282+
2283+ /**
2284+ Destroys the instance.
2285+
2286+ The destructor compacts the database. This ensures that, while a cache is
2287+ not in use, it comsumes as little disk space as possible.
2288+ */
2289+ ~PersistentCache() = default;
2290+
2291+ /** @name Creation Methods
2292+ */
2293+
2294+ //{@
2295+
2296+ /**
2297+ \brief Creates or opens a PersistentCache.
2298+ */
2299+ static UPtr open(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
2300+
2301+ /**
2302+ \brief Opens an existing PersistentCache.
2303+ */
2304+ static UPtr open(std::string const& cache_path);
2305+
2306+ //@}
2307+
2308+ /** @name Accessors
2309+ */
2310+
2311+ //{@
2312+
2313+ /**
2314+ \brief Returns the value of an entry in the cache, provided the entry has not expired.
2315+ */
2316+ OptionalValue get(K const& key) const;
2317+
2318+ /**
2319+ \brief Returns the data for an entry in the cache, provided the entry has not expired.
2320+ */
2321+ OptionalData get_data(K const& key) const;
2322+
2323+ /**
2324+ \brief Returns the metadata for an entry in the cache, provided the entry has not expired.
2325+ */
2326+ OptionalMetadata get_metadata(K const& key) const;
2327+
2328+ /**
2329+ \brief Tests if an (unexpired) entry is in the cache.
2330+ */
2331+ bool contains_key(K const& key) const;
2332+
2333+ /**
2334+ \brief Returns the number of entries in the cache.
2335+ */
2336+ int64_t size() const noexcept;
2337+
2338+ /**
2339+ \brief Returns the number of bytes consumed by entries in the cache.
2340+ */
2341+ int64_t size_in_bytes() const noexcept;
2342+
2343+ /**
2344+ \brief Returns the maximum size of the cache in bytes.
2345+ */
2346+ int64_t max_size_in_bytes() const noexcept;
2347+
2348+ /**
2349+ \brief Returns an estimate of the disk space consumed by the cache.
2350+ */
2351+ int64_t disk_size_in_bytes() const;
2352+
2353+ /**
2354+ \brief Returns the discard policy of the cache.
2355+ */
2356+ CacheDiscardPolicy discard_policy() const noexcept;
2357+
2358+ /**
2359+ \brief Returns statistics for the cache.
2360+ */
2361+ PersistentCacheStats stats() const;
2362+
2363+ //@}
2364+
2365+ /** @name Modifiers
2366+ */
2367+
2368+ //{@
2369+
2370+ /**
2371+ \brief Adds or updates an entry. If `V` = `std::string`, the method is also overloaded to
2372+ to accept `char const*` and `size`.
2373+ */
2374+ bool put(K const& key,
2375+ V const& value,
2376+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
2377+
2378+ /**
2379+ \brief Adds or updates an entry and its metadata. If 'V' or `M` = `std::string`,
2380+ the method is also overloaded to accept `char const*` and `size`.
2381+ */
2382+ bool put(K const& key,
2383+ V const& value,
2384+ M const& metadata,
2385+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
2386+
2387+ /**
2388+ \brief Function called by the cache to load an entry after a cache miss.
2389+ */
2390+ typedef std::function<void(K const& key, PersistentCache<K, V, M>& cache)> Loader;
2391+
2392+ /**
2393+ \brief Atomically retrieves or stores a cache entry.
2394+ */
2395+ OptionalValue get_or_put(K const& key, Loader const& load_func);
2396+
2397+ /**
2398+ \brief Atomically retrieves or stores a cache entry.
2399+ */
2400+ OptionalData get_or_put_data(K const& key, Loader const& load_func);
2401+
2402+ /**
2403+ \brief Adds or replaces the metadata for an entry. If `M` = `std::string`, an overload that accepts
2404+ `const char*` and `size` is provided as well.
2405+ */
2406+ bool put_metadata(K const& key, M const& metadata);
2407+
2408+ /**
2409+ \brief Removes an entry and returns its value.
2410+ */
2411+ OptionalValue take(K const& key);
2412+
2413+ /**
2414+ \brief Removes an entry and returns its value and metadata.
2415+ */
2416+ OptionalData take_data(K const& key);
2417+
2418+ /**
2419+ \brief Removes an entry and its associated metadata (if any).
2420+ */
2421+ bool invalidate(K const& key);
2422+
2423+ /**
2424+ \brief Atomically removes the specified entries from the cache.
2425+ */
2426+ void invalidate(std::vector<K> const& keys);
2427+
2428+ /**
2429+ \brief Atomically removes the specified entries from the cache.
2430+ */
2431+ template <typename It>
2432+ void invalidate(It begin, It end);
2433+
2434+ /**
2435+ \brief Atomically removes the specified entries from the cache.
2436+ */
2437+ void invalidate(std::initializer_list<K> const& keys);
2438+
2439+ /**
2440+ \brief Deletes all entries from the cache.
2441+ */
2442+ void invalidate();
2443+
2444+ /**
2445+ \brief Updates the access time of an entry.
2446+ */
2447+ bool touch(
2448+ K const& key,
2449+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
2450+
2451+ /**
2452+ \brief Resets all statistics counters.
2453+ */
2454+ void clear_stats();
2455+
2456+ /**
2457+ \brief Changes the maximum size of the cache.
2458+ */
2459+ void resize(int64_t size_in_bytes);
2460+
2461+ /**
2462+ \brief Expires entries.
2463+ */
2464+ void trim_to(int64_t used_size_in_bytes);
2465+
2466+ /**
2467+ \brief Compacts the database.
2468+ */
2469+ void compact();
2470+
2471+ //@}
2472+
2473+ /** @name Monitoring cache activity
2474+ */
2475+
2476+ //{@
2477+
2478+ /**
2479+ \brief The type of a handler function.
2480+ */
2481+ typedef std::function<void(K const& key, CacheEvent ev, PersistentCacheStats const& stats)> EventCallback;
2482+
2483+ /**
2484+ \brief Installs a handler for one or more events.
2485+ */
2486+ void set_handler(CacheEvent events, EventCallback cb);
2487+
2488+ //@}
2489+
2490+private:
2491+ // @cond
2492+ PersistentCache(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
2493+ PersistentCache(std::string const& cache_path);
2494+
2495+ std::unique_ptr<PersistentStringCache> p_;
2496+ // @endcond
2497+};
2498+
2499+// @cond
2500+
2501+// Method implementations. Out-of-line because, otherwise, things become completely unreadable.
2502+
2503+template <typename K, typename V, typename M>
2504+PersistentCache<K, V, M>::PersistentCache(std::string const& cache_path,
2505+ int64_t max_size_in_bytes,
2506+ CacheDiscardPolicy policy)
2507+ : p_(PersistentStringCache::open(cache_path, max_size_in_bytes, policy))
2508+{
2509+}
2510+
2511+template <typename K, typename V, typename M>
2512+PersistentCache<K, V, M>::PersistentCache(std::string const& cache_path)
2513+ : p_(PersistentStringCache::open(cache_path))
2514+{
2515+}
2516+
2517+template <typename K, typename V, typename M>
2518+typename PersistentCache<K, V, M>::UPtr PersistentCache<K, V, M>::open(std::string const& cache_path,
2519+ int64_t max_size_in_bytes,
2520+ CacheDiscardPolicy policy)
2521+{
2522+ return PersistentCache<K, V, M>::UPtr(new PersistentCache<K, V, M>(cache_path, max_size_in_bytes, policy));
2523+}
2524+
2525+template <typename K, typename V, typename M>
2526+typename PersistentCache<K, V, M>::UPtr PersistentCache<K, V, M>::open(std::string const& cache_path)
2527+{
2528+ return PersistentCache<K, V, M>::UPtr(new PersistentCache<K, V, M>(cache_path));
2529+}
2530+
2531+template <typename K, typename V, typename M>
2532+typename PersistentCache<K, V, M>::OptionalValue PersistentCache<K, V, M>::get(K const& key) const
2533+{
2534+ auto const& svalue = p_->get(CacheCodec<K>::encode(key));
2535+ return svalue ? OptionalValue(CacheCodec<V>::decode(*svalue)) : OptionalValue();
2536+}
2537+
2538+template <typename K, typename V, typename M>
2539+typename PersistentCache<K, V, M>::OptionalData PersistentCache<K, V, M>::get_data(K const& key) const
2540+{
2541+ auto sdata = p_->get_data(CacheCodec<K>::encode(key));
2542+ if (!sdata)
2543+ {
2544+ return OptionalData();
2545+ }
2546+ return OptionalData({CacheCodec<V>::decode(sdata->value), CacheCodec<M>::decode(sdata->metadata)});
2547+}
2548+
2549+template <typename K, typename V, typename M>
2550+typename PersistentCache<K, V, M>::OptionalMetadata PersistentCache<K, V, M>::get_metadata(K const& key) const
2551+{
2552+ auto smeta = p_->get_metadata(CacheCodec<K>::encode(key));
2553+ return smeta ? OptionalMetadata(CacheCodec<M>::decode(*smeta)) : OptionalMetadata();
2554+}
2555+
2556+template <typename K, typename V, typename M>
2557+bool PersistentCache<K, V, M>::contains_key(K const& key) const
2558+{
2559+ return p_->contains_key(CacheCodec<K>::encode(key));
2560+}
2561+
2562+template <typename K, typename V, typename M>
2563+int64_t PersistentCache<K, V, M>::size() const noexcept
2564+{
2565+ return p_->size();
2566+}
2567+
2568+template <typename K, typename V, typename M>
2569+int64_t PersistentCache<K, V, M>::size_in_bytes() const noexcept
2570+{
2571+ return p_->size_in_bytes();
2572+}
2573+
2574+template <typename K, typename V, typename M>
2575+int64_t PersistentCache<K, V, M>::max_size_in_bytes() const noexcept
2576+{
2577+ return p_->max_size_in_bytes();
2578+}
2579+
2580+template <typename K, typename V, typename M>
2581+int64_t PersistentCache<K, V, M>::disk_size_in_bytes() const
2582+{
2583+ return p_->disk_size_in_bytes();
2584+}
2585+
2586+template <typename K, typename V, typename M>
2587+CacheDiscardPolicy PersistentCache<K, V, M>::discard_policy() const noexcept
2588+{
2589+ return p_->discard_policy();
2590+}
2591+
2592+template <typename K, typename V, typename M>
2593+PersistentCacheStats PersistentCache<K, V, M>::stats() const
2594+{
2595+ return p_->stats();
2596+}
2597+
2598+template <typename K, typename V, typename M>
2599+bool PersistentCache<K, V, M>::put(K const& key,
2600+ V const& value,
2601+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
2602+{
2603+ return p_->put(CacheCodec<K>::encode(key), CacheCodec<V>::encode(value), expiry_time);
2604+}
2605+
2606+template <typename K, typename V, typename M>
2607+bool PersistentCache<K, V, M>::put(K const& key,
2608+ V const& value,
2609+ M const& metadata,
2610+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
2611+{
2612+ return p_->put(CacheCodec<K>::encode(key), CacheCodec<V>::encode(value), CacheCodec<M>::encode(metadata),
2613+ expiry_time);
2614+}
2615+
2616+template <typename K, typename V, typename M>
2617+typename PersistentCache<K, V, M>::OptionalValue PersistentCache<K, V, M>::get_or_put(
2618+ K const& key, PersistentCache<K, V, M>::Loader const& load_func)
2619+{
2620+ std::string const& skey = CacheCodec<K>::encode(key);
2621+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
2622+ {
2623+ load_func(key, *this);
2624+ };
2625+ auto svalue = p_->get_or_put(skey, sload_func);
2626+ return svalue ? OptionalValue(CacheCodec<V>::decode(*svalue)) : OptionalValue();
2627+}
2628+
2629+template <typename K, typename V, typename M>
2630+typename PersistentCache<K, V, M>::OptionalData PersistentCache<K, V, M>::get_or_put_data(
2631+ K const& key, PersistentCache<K, V, M>::Loader const& load_func)
2632+{
2633+ std::string const& skey = CacheCodec<K>::encode(key);
2634+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
2635+ {
2636+ load_func(key, *this);
2637+ };
2638+ auto sdata = p_->get_or_put_data(skey, sload_func);
2639+ if (!sdata)
2640+ {
2641+ return OptionalData();
2642+ }
2643+ return OptionalData({CacheCodec<V>::decode(sdata->value), CacheCodec<M>::decode(sdata->metadata)});
2644+}
2645+
2646+template <typename K, typename V, typename M>
2647+bool PersistentCache<K, V, M>::put_metadata(K const& key, M const& metadata)
2648+{
2649+ return p_->put_metadata(CacheCodec<K>::encode(key), CacheCodec<M>::encode(metadata));
2650+}
2651+
2652+template <typename K, typename V, typename M>
2653+typename PersistentCache<K, V, M>::OptionalValue PersistentCache<K, V, M>::take(K const& key)
2654+{
2655+ auto svalue = p_->take(CacheCodec<K>::encode(key));
2656+ return svalue ? OptionalValue(CacheCodec<V>::decode(*svalue)) : OptionalValue();
2657+}
2658+
2659+template <typename K, typename V, typename M>
2660+typename PersistentCache<K, V, M>::OptionalData PersistentCache<K, V, M>::take_data(K const& key)
2661+{
2662+ auto sdata = p_->take_data(CacheCodec<K>::encode(key));
2663+ if (!sdata)
2664+ {
2665+ return OptionalData();
2666+ }
2667+ return OptionalData({CacheCodec<V>::decode(sdata->value), CacheCodec<M>::decode(sdata->metadata)});
2668+}
2669+
2670+template <typename K, typename V, typename M>
2671+bool PersistentCache<K, V, M>::invalidate(K const& key)
2672+{
2673+ return p_->invalidate(CacheCodec<K>::encode(key));
2674+}
2675+
2676+template <typename K, typename V, typename M>
2677+void PersistentCache<K, V, M>::invalidate(std::vector<K> const& keys)
2678+{
2679+ invalidate(keys.begin(), keys.end());
2680+}
2681+
2682+template <typename K, typename V, typename M>
2683+template <typename It>
2684+void PersistentCache<K, V, M>::invalidate(It begin, It end)
2685+{
2686+ std::vector<std::string> skeys;
2687+ for (auto&& it = begin; it < end; ++it)
2688+ {
2689+ skeys.push_back(CacheCodec<K>::encode(*it));
2690+ }
2691+ p_->invalidate(skeys.begin(), skeys.end());
2692+}
2693+
2694+template <typename K, typename V, typename M>
2695+void PersistentCache<K, V, M>::invalidate(std::initializer_list<K> const& keys)
2696+{
2697+ invalidate(keys.begin(), keys.end());
2698+}
2699+
2700+template <typename K, typename V, typename M>
2701+void PersistentCache<K, V, M>::invalidate()
2702+{
2703+ p_->invalidate();
2704+}
2705+
2706+template <typename K, typename V, typename M>
2707+bool PersistentCache<K, V, M>::touch(K const& key, std::chrono::time_point<std::chrono::system_clock> expiry_time)
2708+{
2709+ return p_->touch(CacheCodec<K>::encode(key), expiry_time);
2710+}
2711+
2712+template <typename K, typename V, typename M>
2713+void PersistentCache<K, V, M>::clear_stats()
2714+{
2715+ p_->clear_stats();
2716+}
2717+
2718+template <typename K, typename V, typename M>
2719+void PersistentCache<K, V, M>::resize(int64_t size_in_bytes)
2720+{
2721+ p_->resize(size_in_bytes);
2722+}
2723+
2724+template <typename K, typename V, typename M>
2725+void PersistentCache<K, V, M>::trim_to(int64_t used_size_in_bytes)
2726+{
2727+ p_->trim_to(used_size_in_bytes);
2728+}
2729+
2730+template <typename K, typename V, typename M>
2731+void PersistentCache<K, V, M>::compact()
2732+{
2733+ p_->compact();
2734+}
2735+
2736+template <typename K, typename V, typename M>
2737+void PersistentCache<K, V, M>::set_handler(CacheEvent events, EventCallback cb)
2738+{
2739+ auto scb = [cb](std::string const& key, CacheEvent ev, PersistentCacheStats const& c)
2740+ {
2741+ cb(CacheCodec<K>::decode(key), ev, c);
2742+ };
2743+ p_->set_handler(events, scb);
2744+}
2745+
2746+// Below are specializations for the various combinations of one or more of K, V, and M
2747+// being of type std::string. Without this, we would end up calling through a string-to-string
2748+// codec, which would force a copy for everything of type string, which is brutally inefficient.
2749+//
2750+// This is verbose because we must specialize the class template in order to avoid
2751+// calling the CacheCodec methods for type string. The combinations that follow are
2752+// <s,V,M>, <K,s,M>, <K,V,s>, <s,s,M>, <s,V,s>, <K,s,s>, and <s,s,s>.
2753+// The code is identical, except that, where we know that K, V, or M are std::string,
2754+// it avoids calling the encode()/decode() methods.
2755+
2756+// Specialization for K = std::string.
2757+
2758+template <typename V, typename M>
2759+class PersistentCache<std::string, V, M>
2760+{
2761+public:
2762+ typedef std::unique_ptr<PersistentCache<std::string, V, M>> UPtr;
2763+
2764+ typedef Optional<std::string> OptionalKey;
2765+ typedef Optional<V> OptionalValue;
2766+ typedef Optional<M> OptionalMetadata;
2767+
2768+ struct Data
2769+ {
2770+ V value;
2771+ M metadata;
2772+ };
2773+ typedef Optional<Data> OptionalData;
2774+
2775+ PersistentCache(PersistentCache const&) = delete;
2776+ PersistentCache& operator=(PersistentCache const&) = delete;
2777+
2778+ PersistentCache(PersistentCache&&) = default;
2779+ PersistentCache& operator=(PersistentCache&&) = default;
2780+
2781+ ~PersistentCache() = default;
2782+
2783+ static UPtr open(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
2784+ static UPtr open(std::string const& cache_path);
2785+
2786+ OptionalValue get(std::string const& key) const;
2787+ OptionalData get_data(std::string const& key) const;
2788+ OptionalMetadata get_metadata(std::string const& key) const;
2789+ bool contains_key(std::string const& key) const;
2790+ int64_t size() const noexcept;
2791+ int64_t size_in_bytes() const noexcept;
2792+ int64_t max_size_in_bytes() const noexcept;
2793+ int64_t disk_size_in_bytes() const;
2794+ CacheDiscardPolicy discard_policy() const noexcept;
2795+ PersistentCacheStats stats() const;
2796+
2797+ bool put(std::string const& key,
2798+ V const& value,
2799+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
2800+ bool put(std::string const& key,
2801+ V const& value,
2802+ M const& metadata,
2803+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
2804+
2805+ typedef std::function<void(std::string const& key, PersistentCache<std::string, V, M>& cache)> Loader;
2806+
2807+ OptionalValue get_or_put(std::string const& key, Loader const& load_func);
2808+ OptionalData get_or_put_data(std::string const& key, Loader const& load_func);
2809+
2810+ bool put_metadata(std::string const& key, M const& metadata);
2811+ OptionalValue take(std::string const& key);
2812+ OptionalData take_data(std::string const& key);
2813+ bool invalidate(std::string const& key);
2814+ void invalidate(std::vector<std::string> const& keys);
2815+ template <typename It>
2816+ void invalidate(It begin, It end);
2817+ void invalidate(std::initializer_list<std::string> const& keys);
2818+ void invalidate();
2819+ bool touch(
2820+ std::string const& key,
2821+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
2822+ void clear_stats();
2823+ void resize(int64_t size_in_bytes);
2824+ void trim_to(int64_t used_size_in_bytes);
2825+ void compact();
2826+
2827+ typedef std::function<void(std::string const& key, CacheEvent ev, PersistentCacheStats const& stats)> EventCallback;
2828+
2829+ void set_handler(CacheEvent events, EventCallback cb);
2830+
2831+private:
2832+ PersistentCache(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
2833+ PersistentCache(std::string const& cache_path);
2834+
2835+ std::unique_ptr<PersistentStringCache> p_;
2836+};
2837+
2838+template <typename V, typename M>
2839+PersistentCache<std::string, V, M>::PersistentCache(std::string const& cache_path,
2840+ int64_t max_size_in_bytes,
2841+ CacheDiscardPolicy policy)
2842+ : p_(PersistentStringCache::open(cache_path, max_size_in_bytes, policy))
2843+{
2844+}
2845+
2846+template <typename V, typename M>
2847+PersistentCache<std::string, V, M>::PersistentCache(std::string const& cache_path)
2848+ : p_(PersistentStringCache::open(cache_path))
2849+{
2850+}
2851+
2852+template <typename V, typename M>
2853+typename PersistentCache<std::string, V, M>::UPtr PersistentCache<std::string, V, M>::open(
2854+ std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy)
2855+{
2856+ return PersistentCache<std::string, V, M>::UPtr(
2857+ new PersistentCache<std::string, V, M>(cache_path, max_size_in_bytes, policy));
2858+}
2859+
2860+template <typename V, typename M>
2861+typename PersistentCache<std::string, V, M>::UPtr PersistentCache<std::string, V, M>::open(
2862+ std::string const& cache_path)
2863+{
2864+ return PersistentCache<std::string, V, M>::UPtr(new PersistentCache<std::string, V, M>(cache_path));
2865+}
2866+
2867+template <typename V, typename M>
2868+typename PersistentCache<std::string, V, M>::OptionalValue PersistentCache<std::string, V, M>::get(
2869+ std::string const& key) const
2870+{
2871+ auto const& svalue = p_->get(key);
2872+ return svalue ? OptionalValue(CacheCodec<V>::decode(*svalue)) : OptionalValue();
2873+}
2874+
2875+template <typename V, typename M>
2876+typename PersistentCache<std::string, V, M>::OptionalData PersistentCache<std::string, V, M>::get_data(
2877+ std::string const& key) const
2878+{
2879+ auto sdata = p_->get_data(key);
2880+ if (!sdata)
2881+ {
2882+ return OptionalData();
2883+ }
2884+ return OptionalData({CacheCodec<V>::decode(sdata->value), CacheCodec<M>::decode(sdata->metadata)});
2885+}
2886+
2887+template <typename V, typename M>
2888+typename PersistentCache<std::string, V, M>::OptionalMetadata PersistentCache<std::string, V, M>::get_metadata(
2889+ std::string const& key) const
2890+{
2891+ auto smeta = p_->get_metadata(key);
2892+ return smeta ? OptionalMetadata(CacheCodec<M>::decode(*smeta)) : OptionalMetadata();
2893+}
2894+
2895+template <typename V, typename M>
2896+bool PersistentCache<std::string, V, M>::contains_key(std::string const& key) const
2897+{
2898+ return p_->contains_key(key);
2899+}
2900+
2901+template <typename V, typename M>
2902+int64_t PersistentCache<std::string, V, M>::size() const noexcept
2903+{
2904+ return p_->size();
2905+}
2906+
2907+template <typename V, typename M>
2908+int64_t PersistentCache<std::string, V, M>::size_in_bytes() const noexcept
2909+{
2910+ return p_->size_in_bytes();
2911+}
2912+
2913+template <typename V, typename M>
2914+int64_t PersistentCache<std::string, V, M>::max_size_in_bytes() const noexcept
2915+{
2916+ return p_->max_size_in_bytes();
2917+}
2918+
2919+template <typename V, typename M>
2920+int64_t PersistentCache<std::string, V, M>::disk_size_in_bytes() const
2921+{
2922+ return p_->disk_size_in_bytes();
2923+}
2924+
2925+template <typename V, typename M>
2926+CacheDiscardPolicy PersistentCache<std::string, V, M>::discard_policy() const noexcept
2927+{
2928+ return p_->discard_policy();
2929+}
2930+
2931+template <typename V, typename M>
2932+PersistentCacheStats PersistentCache<std::string, V, M>::stats() const
2933+{
2934+ return p_->stats();
2935+}
2936+
2937+template <typename V, typename M>
2938+bool PersistentCache<std::string, V, M>::put(std::string const& key,
2939+ V const& value,
2940+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
2941+{
2942+ return p_->put(key, CacheCodec<V>::encode(value), expiry_time);
2943+}
2944+
2945+template <typename V, typename M>
2946+bool PersistentCache<std::string, V, M>::put(std::string const& key,
2947+ V const& value,
2948+ M const& metadata,
2949+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
2950+{
2951+ return p_->put(key, CacheCodec<V>::encode(value), CacheCodec<M>::encode(metadata), expiry_time);
2952+}
2953+
2954+template <typename V, typename M>
2955+typename PersistentCache<std::string, V, M>::OptionalValue PersistentCache<std::string, V, M>::get_or_put(
2956+ std::string const& key, PersistentCache<std::string, V, M>::Loader const& load_func)
2957+{
2958+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
2959+ {
2960+ load_func(key, *this);
2961+ };
2962+ auto svalue = p_->get_or_put(key, sload_func);
2963+ return svalue ? OptionalValue(CacheCodec<V>::decode(*svalue)) : OptionalValue();
2964+}
2965+
2966+template <typename V, typename M>
2967+typename PersistentCache<std::string, V, M>::OptionalData PersistentCache<std::string, V, M>::get_or_put_data(
2968+ std::string const& key, PersistentCache<std::string, V, M>::Loader const& load_func)
2969+{
2970+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
2971+ {
2972+ load_func(key, *this);
2973+ };
2974+ auto sdata = p_->get_or_put_data(key, sload_func);
2975+ if (!sdata)
2976+ {
2977+ return OptionalData();
2978+ }
2979+ return OptionalData({CacheCodec<V>::decode(sdata->value), CacheCodec<M>::decode(sdata->metadata)});
2980+}
2981+
2982+template <typename V, typename M>
2983+bool PersistentCache<std::string, V, M>::put_metadata(std::string const& key, M const& metadata)
2984+{
2985+ return p_->put_metadata(key, CacheCodec<M>::encode(metadata));
2986+}
2987+
2988+template <typename V, typename M>
2989+typename PersistentCache<std::string, V, M>::OptionalValue PersistentCache<std::string, V, M>::take(
2990+ std::string const& key)
2991+{
2992+ auto svalue = p_->take(key);
2993+ return svalue ? OptionalValue(CacheCodec<V>::decode(*svalue)) : OptionalValue();
2994+}
2995+
2996+template <typename V, typename M>
2997+typename PersistentCache<std::string, V, M>::OptionalData PersistentCache<std::string, V, M>::take_data(
2998+ std::string const& key)
2999+{
3000+ auto sdata = p_->take_data(key);
3001+ if (!sdata)
3002+ {
3003+ return OptionalData();
3004+ }
3005+ return OptionalData({CacheCodec<V>::decode(sdata->value), CacheCodec<M>::decode(sdata->metadata)});
3006+}
3007+
3008+template <typename V, typename M>
3009+bool PersistentCache<std::string, V, M>::invalidate(std::string const& key)
3010+{
3011+ return p_->invalidate(key);
3012+}
3013+
3014+template <typename V, typename M>
3015+void PersistentCache<std::string, V, M>::invalidate(std::vector<std::string> const& keys)
3016+{
3017+ invalidate(keys.begin(), keys.end());
3018+}
3019+
3020+template <typename V, typename M>
3021+template <typename It>
3022+void PersistentCache<std::string, V, M>::invalidate(It begin, It end)
3023+{
3024+ std::vector<std::string> skeys;
3025+ for (auto&& it = begin; it < end; ++it)
3026+ {
3027+ skeys.push_back(*it);
3028+ }
3029+ p_->invalidate(skeys.begin(), skeys.end());
3030+}
3031+
3032+template <typename V, typename M>
3033+void PersistentCache<std::string, V, M>::invalidate(std::initializer_list<std::string> const& keys)
3034+{
3035+ invalidate(keys.begin(), keys.end());
3036+}
3037+
3038+template <typename V, typename M>
3039+void PersistentCache<std::string, V, M>::invalidate()
3040+{
3041+ p_->invalidate();
3042+}
3043+
3044+template <typename V, typename M>
3045+bool PersistentCache<std::string, V, M>::touch(std::string const& key,
3046+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
3047+{
3048+ return p_->touch(key, expiry_time);
3049+}
3050+
3051+template <typename V, typename M>
3052+void PersistentCache<std::string, V, M>::clear_stats()
3053+{
3054+ p_->clear_stats();
3055+}
3056+
3057+template <typename V, typename M>
3058+void PersistentCache<std::string, V, M>::resize(int64_t size_in_bytes)
3059+{
3060+ p_->resize(size_in_bytes);
3061+}
3062+
3063+template <typename V, typename M>
3064+void PersistentCache<std::string, V, M>::trim_to(int64_t used_size_in_bytes)
3065+{
3066+ p_->trim_to(used_size_in_bytes);
3067+}
3068+
3069+template <typename V, typename M>
3070+void PersistentCache<std::string, V, M>::compact()
3071+{
3072+ p_->compact();
3073+}
3074+
3075+template <typename V, typename M>
3076+void PersistentCache<std::string, V, M>::set_handler(CacheEvent events, EventCallback cb)
3077+{
3078+ p_->set_handler(events, cb);
3079+}
3080+
3081+// Specialization for V = std::string.
3082+
3083+template <typename K, typename M>
3084+class PersistentCache<K, std::string, M>
3085+{
3086+public:
3087+ typedef std::unique_ptr<PersistentCache<K, std::string, M>> UPtr;
3088+
3089+ typedef Optional<K> OptionalKey;
3090+ typedef Optional<std::string> OptionalValue;
3091+ typedef Optional<M> OptionalMetadata;
3092+
3093+ struct Data
3094+ {
3095+ std::string value;
3096+ M metadata;
3097+ };
3098+ typedef Optional<Data> OptionalData;
3099+
3100+ PersistentCache(PersistentCache const&) = delete;
3101+ PersistentCache& operator=(PersistentCache const&) = delete;
3102+
3103+ PersistentCache(PersistentCache&&) = default;
3104+ PersistentCache& operator=(PersistentCache&&) = default;
3105+
3106+ ~PersistentCache() = default;
3107+
3108+ static UPtr open(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
3109+ static UPtr open(std::string const& cache_path);
3110+
3111+ OptionalValue get(K const& key) const;
3112+ OptionalData get_data(K const& key) const;
3113+ OptionalMetadata get_metadata(K const& key) const;
3114+ bool contains_key(K const& key) const;
3115+ int64_t size() const noexcept;
3116+ int64_t size_in_bytes() const noexcept;
3117+ int64_t max_size_in_bytes() const noexcept;
3118+ int64_t disk_size_in_bytes() const;
3119+ CacheDiscardPolicy discard_policy() const noexcept;
3120+ PersistentCacheStats stats() const;
3121+
3122+ bool put(K const& key,
3123+ std::string const& value,
3124+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3125+ bool put(K const& key,
3126+ char const* value,
3127+ int64_t size,
3128+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3129+ bool put(K const& key,
3130+ std::string const& value,
3131+ M const& metadata,
3132+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3133+ bool put(K const& key,
3134+ char const* value,
3135+ int64_t value_size,
3136+ M const& metadata,
3137+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3138+
3139+ typedef std::function<void(K const& key, PersistentCache<K, std::string, M>& cache)> Loader;
3140+
3141+ OptionalValue get_or_put(K const& key, Loader const& load_func);
3142+ OptionalData get_or_put_data(K const& key, Loader const& load_func);
3143+
3144+ bool put_metadata(K const& key, M const& metadata);
3145+ OptionalValue take(K const& key);
3146+ OptionalData take_data(K const& key);
3147+ bool invalidate(K const& key);
3148+ void invalidate(std::vector<K> const& keys);
3149+ template <typename It>
3150+ void invalidate(It begin, It end);
3151+ void invalidate(std::initializer_list<K> const& keys);
3152+ void invalidate();
3153+ bool touch(
3154+ K const& key,
3155+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3156+ void clear_stats();
3157+ void resize(int64_t size_in_bytes);
3158+ void trim_to(int64_t used_size_in_bytes);
3159+ void compact();
3160+
3161+ typedef std::function<void(K const& key, CacheEvent ev, PersistentCacheStats const& stats)> EventCallback;
3162+
3163+ void set_handler(CacheEvent events, EventCallback cb);
3164+
3165+private:
3166+ PersistentCache(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
3167+ PersistentCache(std::string const& cache_path);
3168+
3169+ std::unique_ptr<PersistentStringCache> p_;
3170+};
3171+
3172+template <typename K, typename M>
3173+PersistentCache<K, std::string, M>::PersistentCache(std::string const& cache_path,
3174+ int64_t max_size_in_bytes,
3175+ CacheDiscardPolicy policy)
3176+ : p_(PersistentStringCache::open(cache_path, max_size_in_bytes, policy))
3177+{
3178+}
3179+
3180+template <typename K, typename M>
3181+PersistentCache<K, std::string, M>::PersistentCache(std::string const& cache_path)
3182+ : p_(PersistentStringCache::open(cache_path))
3183+{
3184+}
3185+
3186+template <typename K, typename M>
3187+typename PersistentCache<K, std::string, M>::UPtr PersistentCache<K, std::string, M>::open(
3188+ std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy)
3189+{
3190+ return PersistentCache<K, std::string, M>::UPtr(
3191+ new PersistentCache<K, std::string, M>(cache_path, max_size_in_bytes, policy));
3192+}
3193+
3194+template <typename K, typename M>
3195+typename PersistentCache<K, std::string, M>::UPtr PersistentCache<K, std::string, M>::open(
3196+ std::string const& cache_path)
3197+{
3198+ return PersistentCache<K, std::string, M>::UPtr(new PersistentCache<K, std::string, M>(cache_path));
3199+}
3200+
3201+template <typename K, typename M>
3202+typename PersistentCache<K, std::string, M>::OptionalValue PersistentCache<K, std::string, M>::get(K const& key) const
3203+{
3204+ auto const& svalue = p_->get(CacheCodec<K>::encode(key));
3205+ return svalue ? OptionalValue(*svalue) : OptionalValue();
3206+}
3207+
3208+template <typename K, typename M>
3209+typename PersistentCache<K, std::string, M>::OptionalData PersistentCache<K, std::string, M>::get_data(
3210+ K const& key) const
3211+{
3212+ auto sdata = p_->get_data(CacheCodec<K>::encode(key));
3213+ if (!sdata)
3214+ {
3215+ return OptionalData();
3216+ }
3217+ return OptionalData({sdata->value, CacheCodec<M>::decode(sdata->metadata)});
3218+}
3219+
3220+template <typename K, typename M>
3221+typename PersistentCache<K, std::string, M>::OptionalMetadata PersistentCache<K, std::string, M>::get_metadata(
3222+ K const& key) const
3223+{
3224+ auto smeta = p_->get_metadata(CacheCodec<K>::encode(key));
3225+ return smeta ? OptionalMetadata(CacheCodec<M>::decode(*smeta)) : OptionalMetadata();
3226+}
3227+
3228+template <typename K, typename M>
3229+bool PersistentCache<K, std::string, M>::contains_key(K const& key) const
3230+{
3231+ return p_->contains_key(CacheCodec<K>::encode(key));
3232+}
3233+
3234+template <typename K, typename M>
3235+int64_t PersistentCache<K, std::string, M>::size() const noexcept
3236+{
3237+ return p_->size();
3238+}
3239+
3240+template <typename K, typename M>
3241+int64_t PersistentCache<K, std::string, M>::size_in_bytes() const noexcept
3242+{
3243+ return p_->size_in_bytes();
3244+}
3245+
3246+template <typename K, typename M>
3247+int64_t PersistentCache<K, std::string, M>::max_size_in_bytes() const noexcept
3248+{
3249+ return p_->max_size_in_bytes();
3250+}
3251+
3252+template <typename K, typename M>
3253+int64_t PersistentCache<K, std::string, M>::disk_size_in_bytes() const
3254+{
3255+ return p_->disk_size_in_bytes();
3256+}
3257+
3258+template <typename K, typename M>
3259+CacheDiscardPolicy PersistentCache<K, std::string, M>::discard_policy() const noexcept
3260+{
3261+ return p_->discard_policy();
3262+}
3263+
3264+template <typename K, typename M>
3265+PersistentCacheStats PersistentCache<K, std::string, M>::stats() const
3266+{
3267+ return p_->stats();
3268+}
3269+
3270+template <typename K, typename M>
3271+bool PersistentCache<K, std::string, M>::put(K const& key,
3272+ std::string const& value,
3273+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
3274+{
3275+ return p_->put(CacheCodec<K>::encode(key), value, expiry_time);
3276+}
3277+
3278+template <typename K, typename M>
3279+bool PersistentCache<K, std::string, M>::put(K const& key,
3280+ char const* value,
3281+ int64_t size,
3282+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
3283+{
3284+ return p_->put(CacheCodec<K>::encode(key), value, size, expiry_time);
3285+}
3286+
3287+template <typename K, typename M>
3288+bool PersistentCache<K, std::string, M>::put(K const& key,
3289+ std::string const& value,
3290+ M const& metadata,
3291+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
3292+{
3293+ return p_->put(CacheCodec<K>::encode(key), value, CacheCodec<M>::encode(metadata), expiry_time);
3294+}
3295+
3296+template <typename K, typename M>
3297+bool PersistentCache<K, std::string, M>::put(K const& key,
3298+ char const* value,
3299+ int64_t size,
3300+ M const& metadata,
3301+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
3302+{
3303+ std::string md = CacheCodec<M>::encode(metadata);
3304+ return p_->put(CacheCodec<K>::encode(key), value, size, md.data(), md.size(), expiry_time);
3305+}
3306+
3307+template <typename K, typename M>
3308+typename PersistentCache<K, std::string, M>::OptionalValue PersistentCache<K, std::string, M>::get_or_put(
3309+ K const& key, PersistentCache<K, std::string, M>::Loader const& load_func)
3310+{
3311+ std::string const& skey = CacheCodec<K>::encode(key);
3312+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
3313+ {
3314+ load_func(key, *this);
3315+ };
3316+ auto svalue = p_->get_or_put(skey, sload_func);
3317+ return svalue ? OptionalValue(*svalue) : OptionalValue();
3318+}
3319+
3320+template <typename K, typename M>
3321+typename PersistentCache<K, std::string, M>::OptionalData PersistentCache<K, std::string, M>::get_or_put_data(
3322+ K const& key, PersistentCache<K, std::string, M>::Loader const& load_func)
3323+{
3324+ std::string const& skey = CacheCodec<K>::encode(key);
3325+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
3326+ {
3327+ load_func(key, *this);
3328+ };
3329+ auto sdata = p_->get_or_put_data(skey, sload_func);
3330+ if (!sdata)
3331+ {
3332+ return OptionalData();
3333+ }
3334+ return OptionalData({sdata->value, CacheCodec<M>::decode(sdata->metadata)});
3335+}
3336+
3337+template <typename K, typename M>
3338+bool PersistentCache<K, std::string, M>::put_metadata(K const& key, M const& metadata)
3339+{
3340+ return p_->put_metadata(CacheCodec<K>::encode(key), CacheCodec<M>::encode(metadata));
3341+}
3342+
3343+template <typename K, typename M>
3344+typename PersistentCache<K, std::string, M>::OptionalValue PersistentCache<K, std::string, M>::take(K const& key)
3345+{
3346+ auto svalue = p_->take(CacheCodec<K>::encode(key));
3347+ return svalue ? OptionalValue(*svalue) : OptionalValue();
3348+}
3349+
3350+template <typename K, typename M>
3351+typename PersistentCache<K, std::string, M>::OptionalData PersistentCache<K, std::string, M>::take_data(
3352+ K const& key)
3353+{
3354+ auto sdata = p_->take_data(CacheCodec<K>::encode(key));
3355+ if (!sdata)
3356+ {
3357+ return OptionalData();
3358+ }
3359+ return OptionalData({sdata->value, CacheCodec<M>::decode(sdata->metadata)});
3360+}
3361+
3362+template <typename K, typename M>
3363+bool PersistentCache<K, std::string, M>::invalidate(K const& key)
3364+{
3365+ return p_->invalidate(CacheCodec<K>::encode(key));
3366+}
3367+
3368+template <typename K, typename M>
3369+void PersistentCache<K, std::string, M>::invalidate(std::vector<K> const& keys)
3370+{
3371+ invalidate(keys.begin(), keys.end());
3372+}
3373+
3374+template <typename K, typename M>
3375+template <typename It>
3376+void PersistentCache<K, std::string, M>::invalidate(It begin, It end)
3377+{
3378+ std::vector<std::string> skeys;
3379+ for (auto&& it = begin; it < end; ++it)
3380+ {
3381+ skeys.push_back(CacheCodec<K>::encode(*it));
3382+ }
3383+ p_->invalidate(skeys.begin(), skeys.end());
3384+}
3385+
3386+template <typename K, typename M>
3387+void PersistentCache<K, std::string, M>::invalidate(std::initializer_list<K> const& keys)
3388+{
3389+ invalidate(keys.begin(), keys.end());
3390+}
3391+
3392+template <typename K, typename M>
3393+void PersistentCache<K, std::string, M>::invalidate()
3394+{
3395+ p_->invalidate();
3396+}
3397+
3398+template <typename K, typename M>
3399+bool PersistentCache<K, std::string, M>::touch(K const& key,
3400+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
3401+{
3402+ return p_->touch(CacheCodec<K>::encode(key), expiry_time);
3403+}
3404+
3405+template <typename K, typename M>
3406+void PersistentCache<K, std::string, M>::clear_stats()
3407+{
3408+ p_->clear_stats();
3409+}
3410+
3411+template <typename K, typename M>
3412+void PersistentCache<K, std::string, M>::resize(int64_t size_in_bytes)
3413+{
3414+ p_->resize(size_in_bytes);
3415+}
3416+
3417+template <typename K, typename M>
3418+void PersistentCache<K, std::string, M>::trim_to(int64_t used_size_in_bytes)
3419+{
3420+ p_->trim_to(used_size_in_bytes);
3421+}
3422+
3423+template <typename K, typename M>
3424+void PersistentCache<K, std::string, M>::compact()
3425+{
3426+ p_->compact();
3427+}
3428+
3429+template <typename K, typename M>
3430+void PersistentCache<K, std::string, M>::set_handler(CacheEvent events, EventCallback cb)
3431+{
3432+ auto scb = [cb](std::string const& key, CacheEvent ev, PersistentCacheStats const& c)
3433+ {
3434+ cb(CacheCodec<K>::decode(key), ev, c);
3435+ };
3436+ p_->set_handler(events, scb);
3437+}
3438+
3439+// Specialization for M = std::string.
3440+
3441+template <typename K, typename V>
3442+class PersistentCache<K, V, std::string>
3443+{
3444+public:
3445+ typedef std::unique_ptr<PersistentCache<K, V, std::string>> UPtr;
3446+
3447+ typedef Optional<K> OptionalKey;
3448+ typedef Optional<V> OptionalValue;
3449+ typedef Optional<std::string> OptionalMetadata;
3450+
3451+ struct Data
3452+ {
3453+ V value;
3454+ std::string metadata;
3455+ };
3456+ typedef Optional<Data> OptionalData;
3457+
3458+ PersistentCache(PersistentCache const&) = delete;
3459+ PersistentCache& operator=(PersistentCache const&) = delete;
3460+
3461+ PersistentCache(PersistentCache&&) = default;
3462+ PersistentCache& operator=(PersistentCache&&) = default;
3463+
3464+ ~PersistentCache() = default;
3465+
3466+ static UPtr open(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
3467+ static UPtr open(std::string const& cache_path);
3468+
3469+ OptionalValue get(K const& key) const;
3470+ OptionalData get_data(K const& key) const;
3471+ OptionalMetadata get_metadata(K const& key) const;
3472+ bool contains_key(K const& key) const;
3473+ int64_t size() const noexcept;
3474+ int64_t size_in_bytes() const noexcept;
3475+ int64_t max_size_in_bytes() const noexcept;
3476+ int64_t disk_size_in_bytes() const;
3477+ CacheDiscardPolicy discard_policy() const noexcept;
3478+ PersistentCacheStats stats() const;
3479+
3480+ bool put(K const& key,
3481+ V const& value,
3482+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3483+ bool put(K const& key,
3484+ V const& value,
3485+ std::string const& metadata,
3486+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3487+ bool put(K const& key,
3488+ V const& value,
3489+ char const* metadata,
3490+ int64_t size,
3491+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3492+
3493+ typedef std::function<void(K const& key, PersistentCache<K, V, std::string>& cache)> Loader;
3494+
3495+ OptionalValue get_or_put(K const& key, Loader const& load_func);
3496+ OptionalData get_or_put_data(K const& key, Loader const& load_func);
3497+
3498+ bool put_metadata(K const& key, std::string const& metadata);
3499+ bool put_metadata(K const& key, char const* metadata, int64_t size);
3500+ OptionalValue take(K const& key);
3501+ OptionalData take_data(K const& key);
3502+ bool invalidate(K const& key);
3503+ void invalidate(std::vector<K> const& keys);
3504+ template <typename It>
3505+ void invalidate(It begin, It end);
3506+ void invalidate(std::initializer_list<K> const& keys);
3507+ void invalidate();
3508+ bool touch(
3509+ K const& key,
3510+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3511+ void clear_stats();
3512+ void resize(int64_t size_in_bytes);
3513+ void trim_to(int64_t used_size_in_bytes);
3514+ void compact();
3515+
3516+ typedef std::function<void(K const& key, CacheEvent ev, PersistentCacheStats const& stats)> EventCallback;
3517+
3518+ void set_handler(CacheEvent events, EventCallback cb);
3519+
3520+private:
3521+ PersistentCache(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
3522+ PersistentCache(std::string const& cache_path);
3523+
3524+ std::unique_ptr<PersistentStringCache> p_;
3525+};
3526+
3527+template <typename K, typename V>
3528+PersistentCache<K, V, std::string>::PersistentCache(std::string const& cache_path,
3529+ int64_t max_size_in_bytes,
3530+ CacheDiscardPolicy policy)
3531+ : p_(PersistentStringCache::open(cache_path, max_size_in_bytes, policy))
3532+{
3533+}
3534+
3535+template <typename K, typename V>
3536+PersistentCache<K, V, std::string>::PersistentCache(std::string const& cache_path)
3537+ : p_(PersistentStringCache::open(cache_path))
3538+{
3539+}
3540+
3541+template <typename K, typename V>
3542+typename PersistentCache<K, V, std::string>::UPtr PersistentCache<K, V, std::string>::open(
3543+ std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy)
3544+{
3545+ return PersistentCache<K, V, std::string>::UPtr(
3546+ new PersistentCache<K, V, std::string>(cache_path, max_size_in_bytes, policy));
3547+}
3548+
3549+template <typename K, typename V>
3550+typename PersistentCache<K, V, std::string>::UPtr PersistentCache<K, V, std::string>::open(
3551+ std::string const& cache_path)
3552+{
3553+ return PersistentCache<K, V, std::string>::UPtr(new PersistentCache<K, V, std::string>(cache_path));
3554+}
3555+
3556+template <typename K, typename V>
3557+typename PersistentCache<K, V, std::string>::OptionalValue PersistentCache<K, V, std::string>::get(K const& key) const
3558+{
3559+ auto const& svalue = p_->get(CacheCodec<K>::encode(key));
3560+ return svalue ? OptionalValue(CacheCodec<V>::decode(*svalue)) : OptionalValue();
3561+}
3562+
3563+template <typename K, typename V>
3564+typename PersistentCache<K, V, std::string>::OptionalData PersistentCache<K, V, std::string>::get_data(
3565+ K const& key) const
3566+{
3567+ auto sdata = p_->get_data(CacheCodec<K>::encode(key));
3568+ if (!sdata)
3569+ {
3570+ return OptionalData();
3571+ }
3572+ return OptionalData({CacheCodec<V>::decode(sdata->value), sdata->metadata});
3573+}
3574+
3575+template <typename K, typename V>
3576+typename PersistentCache<K, V, std::string>::OptionalMetadata PersistentCache<K, V, std::string>::get_metadata(
3577+ K const& key) const
3578+{
3579+ auto smeta = p_->get_metadata(CacheCodec<K>::encode(key));
3580+ return smeta ? OptionalMetadata(*smeta) : OptionalMetadata();
3581+}
3582+
3583+template <typename K, typename V>
3584+bool PersistentCache<K, V, std::string>::contains_key(K const& key) const
3585+{
3586+ return p_->contains_key(CacheCodec<K>::encode(key));
3587+}
3588+
3589+template <typename K, typename V>
3590+int64_t PersistentCache<K, V, std::string>::size() const noexcept
3591+{
3592+ return p_->size();
3593+}
3594+
3595+template <typename K, typename V>
3596+int64_t PersistentCache<K, V, std::string>::size_in_bytes() const noexcept
3597+{
3598+ return p_->size_in_bytes();
3599+}
3600+
3601+template <typename K, typename V>
3602+int64_t PersistentCache<K, V, std::string>::max_size_in_bytes() const noexcept
3603+{
3604+ return p_->max_size_in_bytes();
3605+}
3606+
3607+template <typename K, typename V>
3608+int64_t PersistentCache<K, V, std::string>::disk_size_in_bytes() const
3609+{
3610+ return p_->disk_size_in_bytes();
3611+}
3612+
3613+template <typename K, typename V>
3614+CacheDiscardPolicy PersistentCache<K, V, std::string>::discard_policy() const noexcept
3615+{
3616+ return p_->discard_policy();
3617+}
3618+
3619+template <typename K, typename V>
3620+PersistentCacheStats PersistentCache<K, V, std::string>::stats() const
3621+{
3622+ return p_->stats();
3623+}
3624+
3625+template <typename K, typename V>
3626+bool PersistentCache<K, V, std::string>::put(K const& key,
3627+ V const& value,
3628+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
3629+{
3630+ return p_->put(CacheCodec<K>::encode(key), CacheCodec<V>::encode(value), expiry_time);
3631+}
3632+
3633+template <typename K, typename V>
3634+bool PersistentCache<K, V, std::string>::put(K const& key,
3635+ V const& value,
3636+ std::string const& metadata,
3637+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
3638+{
3639+ std::string v = CacheCodec<V>::encode(value);
3640+ return p_->put(CacheCodec<K>::encode(key), v.data(), v.size(), metadata.data(), metadata.size(), expiry_time);
3641+}
3642+
3643+template <typename K, typename V>
3644+bool PersistentCache<K, V, std::string>::put(K const& key,
3645+ V const& value,
3646+ char const* metadata,
3647+ int64_t size,
3648+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
3649+{
3650+ std::string v = CacheCodec<V>::encode(value);
3651+ return p_->put(CacheCodec<K>::encode(key), v.data(), v.size(), metadata, size, expiry_time);
3652+}
3653+
3654+template <typename K, typename V>
3655+typename PersistentCache<K, V, std::string>::OptionalValue PersistentCache<K, V, std::string>::get_or_put(
3656+ K const& key, PersistentCache<K, V, std::string>::Loader const& load_func)
3657+{
3658+ std::string const& skey = CacheCodec<K>::encode(key);
3659+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
3660+ {
3661+ load_func(key, *this);
3662+ };
3663+ auto svalue = p_->get_or_put(skey, sload_func);
3664+ return svalue ? OptionalValue(CacheCodec<V>::decode(*svalue)) : OptionalValue();
3665+}
3666+
3667+template <typename K, typename V>
3668+typename PersistentCache<K, V, std::string>::OptionalData PersistentCache<K, V, std::string>::get_or_put_data(
3669+ K const& key, PersistentCache<K, V, std::string>::Loader const& load_func)
3670+{
3671+ std::string const& skey = CacheCodec<K>::encode(key);
3672+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
3673+ {
3674+ load_func(key, *this);
3675+ };
3676+ auto sdata = p_->get_or_put_data(skey, sload_func);
3677+ if (!sdata)
3678+ {
3679+ return OptionalData();
3680+ }
3681+ return OptionalData({CacheCodec<V>::decode(sdata->value), sdata->metadata});
3682+}
3683+
3684+template <typename K, typename V>
3685+bool PersistentCache<K, V, std::string>::put_metadata(K const& key, std::string const& metadata)
3686+{
3687+ return p_->put_metadata(CacheCodec<K>::encode(key), metadata);
3688+}
3689+
3690+template <typename K, typename V>
3691+bool PersistentCache<K, V, std::string>::put_metadata(K const& key, char const* metadata, int64_t size)
3692+{
3693+ return p_->put_metadata(CacheCodec<K>::encode(key), metadata, size);
3694+}
3695+
3696+template <typename K, typename V>
3697+typename PersistentCache<K, V, std::string>::OptionalValue PersistentCache<K, V, std::string>::take(K const& key)
3698+{
3699+ auto svalue = p_->take(CacheCodec<K>::encode(key));
3700+ return svalue ? OptionalValue(CacheCodec<V>::decode(*svalue)) : OptionalValue();
3701+}
3702+
3703+template <typename K, typename V>
3704+typename PersistentCache<K, V, std::string>::OptionalData PersistentCache<K, V, std::string>::take_data(
3705+ K const& key)
3706+{
3707+ auto sdata = p_->take_data(CacheCodec<K>::encode(key));
3708+ if (!sdata)
3709+ {
3710+ return OptionalData();
3711+ }
3712+ return OptionalData({CacheCodec<V>::decode(sdata->value), sdata->metadata});
3713+}
3714+
3715+template <typename K, typename V>
3716+bool PersistentCache<K, V, std::string>::invalidate(K const& key)
3717+{
3718+ return p_->invalidate(CacheCodec<K>::encode(key));
3719+}
3720+
3721+template <typename K, typename V>
3722+void PersistentCache<K, V, std::string>::invalidate(std::vector<K> const& keys)
3723+{
3724+ invalidate(keys.begin(), keys.end());
3725+}
3726+
3727+template <typename K, typename V>
3728+template <typename It>
3729+void PersistentCache<K, V, std::string>::invalidate(It begin, It end)
3730+{
3731+ std::vector<std::string> skeys;
3732+ for (auto&& it = begin; it < end; ++it)
3733+ {
3734+ skeys.push_back(CacheCodec<K>::encode(*it));
3735+ }
3736+ p_->invalidate(skeys.begin(), skeys.end());
3737+}
3738+
3739+template <typename K, typename V>
3740+void PersistentCache<K, V, std::string>::invalidate(std::initializer_list<K> const& keys)
3741+{
3742+ invalidate(keys.begin(), keys.end());
3743+}
3744+
3745+template <typename K, typename V>
3746+void PersistentCache<K, V, std::string>::invalidate()
3747+{
3748+ p_->invalidate();
3749+}
3750+
3751+template <typename K, typename V>
3752+bool PersistentCache<K, V, std::string>::touch(K const& key,
3753+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
3754+{
3755+ return p_->touch(CacheCodec<K>::encode(key), expiry_time);
3756+}
3757+
3758+template <typename K, typename V>
3759+void PersistentCache<K, V, std::string>::clear_stats()
3760+{
3761+ p_->clear_stats();
3762+}
3763+
3764+template <typename K, typename V>
3765+void PersistentCache<K, V, std::string>::resize(int64_t size_in_bytes)
3766+{
3767+ p_->resize(size_in_bytes);
3768+}
3769+
3770+template <typename K, typename V>
3771+void PersistentCache<K, V, std::string>::trim_to(int64_t used_size_in_bytes)
3772+{
3773+ p_->trim_to(used_size_in_bytes);
3774+}
3775+
3776+template <typename K, typename V>
3777+void PersistentCache<K, V, std::string>::compact()
3778+{
3779+ p_->compact();
3780+}
3781+
3782+template <typename K, typename V>
3783+void PersistentCache<K, V, std::string>::set_handler(CacheEvent events, EventCallback cb)
3784+{
3785+ auto scb = [cb](std::string const& key, CacheEvent ev, PersistentCacheStats const& c)
3786+ {
3787+ cb(CacheCodec<K>::decode(key), ev, c);
3788+ };
3789+ p_->set_handler(events, scb);
3790+}
3791+
3792+// Specialization for K and V = std::string.
3793+
3794+template <typename M>
3795+class PersistentCache<std::string, std::string, M>
3796+{
3797+public:
3798+ typedef std::unique_ptr<PersistentCache<std::string, std::string, M>> UPtr;
3799+
3800+ typedef Optional<std::string> OptionalKey;
3801+ typedef Optional<std::string> OptionalValue;
3802+ typedef Optional<M> OptionalMetadata;
3803+
3804+ struct Data
3805+ {
3806+ std::string value;
3807+ M metadata;
3808+ };
3809+ typedef Optional<Data> OptionalData;
3810+
3811+ PersistentCache(PersistentCache const&) = delete;
3812+ PersistentCache& operator=(PersistentCache const&) = delete;
3813+
3814+ PersistentCache(PersistentCache&&) = default;
3815+ PersistentCache& operator=(PersistentCache&&) = default;
3816+
3817+ ~PersistentCache() = default;
3818+
3819+ static UPtr open(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
3820+ static UPtr open(std::string const& cache_path);
3821+
3822+ OptionalValue get(std::string const& key) const;
3823+ OptionalData get_data(std::string const& key) const;
3824+ OptionalMetadata get_metadata(std::string const& key) const;
3825+ bool contains_key(std::string const& key) const;
3826+ int64_t size() const noexcept;
3827+ int64_t size_in_bytes() const noexcept;
3828+ int64_t max_size_in_bytes() const noexcept;
3829+ int64_t disk_size_in_bytes() const;
3830+ CacheDiscardPolicy discard_policy() const noexcept;
3831+ PersistentCacheStats stats() const;
3832+
3833+ bool put(std::string const& key,
3834+ std::string const& value,
3835+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3836+ bool put(std::string const& key,
3837+ char const* value,
3838+ int64_t size,
3839+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3840+ bool put(std::string const& key,
3841+ std::string const& value,
3842+ M const& metadata,
3843+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3844+ bool put(std::string const& key,
3845+ char const* value,
3846+ int64_t value_size,
3847+ M const& metadata,
3848+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3849+
3850+ typedef std::function<void(std::string const& key, PersistentCache<std::string, std::string, M>& cache)> Loader;
3851+
3852+ OptionalValue get_or_put(std::string const& key, Loader const& load_func);
3853+ OptionalData get_or_put_data(std::string const& key, Loader const& load_func);
3854+
3855+ bool put_metadata(std::string const& key, M const& metadata);
3856+ OptionalValue take(std::string const& key);
3857+ OptionalData take_data(std::string const& key);
3858+ bool invalidate(std::string const& key);
3859+ void invalidate(std::vector<std::string> const& keys);
3860+ template <typename It>
3861+ void invalidate(It begin, It end);
3862+ void invalidate(std::initializer_list<std::string> const& keys);
3863+ void invalidate();
3864+ bool touch(
3865+ std::string const& key,
3866+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
3867+ void clear_stats();
3868+ void resize(int64_t size_in_bytes);
3869+ void trim_to(int64_t used_size_in_bytes);
3870+ void compact();
3871+
3872+ typedef std::function<void(std::string const& key, CacheEvent ev, PersistentCacheStats const& stats)> EventCallback;
3873+
3874+ void set_handler(CacheEvent events, EventCallback cb);
3875+
3876+private:
3877+ PersistentCache(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
3878+ PersistentCache(std::string const& cache_path);
3879+
3880+ std::unique_ptr<PersistentStringCache> p_;
3881+};
3882+
3883+template <typename M>
3884+PersistentCache<std::string, std::string, M>::PersistentCache(std::string const& cache_path,
3885+ int64_t max_size_in_bytes,
3886+ CacheDiscardPolicy policy)
3887+ : p_(PersistentStringCache::open(cache_path, max_size_in_bytes, policy))
3888+{
3889+}
3890+
3891+template <typename M>
3892+PersistentCache<std::string, std::string, M>::PersistentCache(std::string const& cache_path)
3893+ : p_(PersistentStringCache::open(cache_path))
3894+{
3895+}
3896+
3897+template <typename M>
3898+typename PersistentCache<std::string, std::string, M>::UPtr PersistentCache<std::string, std::string, M>::open(
3899+ std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy)
3900+{
3901+ return PersistentCache<std::string, std::string, M>::UPtr(
3902+ new PersistentCache<std::string, std::string, M>(cache_path, max_size_in_bytes, policy));
3903+}
3904+
3905+template <typename M>
3906+typename PersistentCache<std::string, std::string, M>::UPtr PersistentCache<std::string, std::string, M>::open(
3907+ std::string const& cache_path)
3908+{
3909+ return PersistentCache<std::string, std::string, M>::UPtr(
3910+ new PersistentCache<std::string, std::string, M>(cache_path));
3911+}
3912+
3913+template <typename M>
3914+typename PersistentCache<std::string, std::string, M>::OptionalValue PersistentCache<std::string, std::string, M>::get(
3915+ std::string const& key) const
3916+{
3917+ auto const& svalue = p_->get(key);
3918+ return svalue ? OptionalValue(*svalue) : OptionalValue();
3919+}
3920+
3921+template <typename M>
3922+typename PersistentCache<std::string, std::string, M>::OptionalData
3923+ PersistentCache<std::string, std::string, M>::get_data(std::string const& key) const
3924+{
3925+ auto sdata = p_->get_data(key);
3926+ if (!sdata)
3927+ {
3928+ return OptionalData();
3929+ }
3930+ return OptionalData({sdata->value, CacheCodec<M>::decode(sdata->metadata)});
3931+}
3932+
3933+template <typename M>
3934+typename PersistentCache<std::string, std::string, M>::OptionalMetadata
3935+ PersistentCache<std::string, std::string, M>::get_metadata(std::string const& key) const
3936+{
3937+ auto smeta = p_->get_metadata(key);
3938+ return smeta ? OptionalMetadata(CacheCodec<M>::decode(*smeta)) : OptionalMetadata();
3939+}
3940+
3941+template <typename M>
3942+bool PersistentCache<std::string, std::string, M>::contains_key(std::string const& key) const
3943+{
3944+ return p_->contains_key(key);
3945+}
3946+
3947+template <typename M>
3948+int64_t PersistentCache<std::string, std::string, M>::size() const noexcept
3949+{
3950+ return p_->size();
3951+}
3952+
3953+template <typename M>
3954+int64_t PersistentCache<std::string, std::string, M>::size_in_bytes() const noexcept
3955+{
3956+ return p_->size_in_bytes();
3957+}
3958+
3959+template <typename M>
3960+int64_t PersistentCache<std::string, std::string, M>::max_size_in_bytes() const noexcept
3961+{
3962+ return p_->max_size_in_bytes();
3963+}
3964+
3965+template <typename M>
3966+int64_t PersistentCache<std::string, std::string, M>::disk_size_in_bytes() const
3967+{
3968+ return p_->disk_size_in_bytes();
3969+}
3970+
3971+template <typename M>
3972+CacheDiscardPolicy PersistentCache<std::string, std::string, M>::discard_policy() const noexcept
3973+{
3974+ return p_->discard_policy();
3975+}
3976+
3977+template <typename M>
3978+PersistentCacheStats PersistentCache<std::string, std::string, M>::stats() const
3979+{
3980+ return p_->stats();
3981+}
3982+
3983+template <typename M>
3984+bool PersistentCache<std::string, std::string, M>::put(std::string const& key,
3985+ std::string const& value,
3986+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
3987+{
3988+ return p_->put(key, value, expiry_time);
3989+}
3990+
3991+template <typename M>
3992+bool PersistentCache<std::string, std::string, M>::put(std::string const& key,
3993+ char const* value,
3994+ int64_t size,
3995+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
3996+{
3997+ return p_->put(key, value, size, nullptr, 0, expiry_time);
3998+}
3999+
4000+template <typename M>
4001+bool PersistentCache<std::string, std::string, M>::put(std::string const& key,
4002+ std::string const& value,
4003+ M const& metadata,
4004+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
4005+{
4006+ return p_->put(key, value, CacheCodec<M>::encode(metadata), expiry_time);
4007+}
4008+
4009+template <typename M>
4010+bool PersistentCache<std::string, std::string, M>::put(std::string const& key,
4011+ char const* value,
4012+ int64_t size,
4013+ M const& metadata,
4014+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
4015+{
4016+ std::string md = CacheCodec<M>::encode(metadata);
4017+ return p_->put(key, value, size, md.data(), md.size(), expiry_time);
4018+}
4019+
4020+template <typename M>
4021+typename PersistentCache<std::string, std::string, M>::OptionalValue
4022+ PersistentCache<std::string, std::string, M>::get_or_put(
4023+ std::string const& key, PersistentCache<std::string, std::string, M>::Loader const& load_func)
4024+{
4025+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
4026+ {
4027+ load_func(key, *this);
4028+ };
4029+ auto svalue = p_->get_or_put(key, sload_func);
4030+ return svalue ? OptionalValue(*svalue) : OptionalValue();
4031+}
4032+
4033+template <typename M>
4034+typename PersistentCache<std::string, std::string, M>::OptionalData
4035+ PersistentCache<std::string, std::string, M>::get_or_put_data(
4036+ std::string const& key, PersistentCache<std::string, std::string, M>::Loader const& load_func)
4037+{
4038+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
4039+ {
4040+ load_func(key, *this);
4041+ };
4042+ auto sdata = p_->get_or_put_data(key, sload_func);
4043+ if (!sdata)
4044+ {
4045+ return OptionalData();
4046+ }
4047+ return OptionalData({sdata->value, CacheCodec<M>::decode(sdata->metadata)});
4048+}
4049+
4050+template <typename M>
4051+bool PersistentCache<std::string, std::string, M>::put_metadata(std::string const& key, M const& metadata)
4052+{
4053+ return p_->put_metadata(key, CacheCodec<M>::encode(metadata));
4054+}
4055+
4056+template <typename M>
4057+typename PersistentCache<std::string, std::string, M>::OptionalValue PersistentCache<std::string, std::string, M>::take(
4058+ std::string const& key)
4059+{
4060+ auto svalue = p_->take(key);
4061+ return svalue ? OptionalValue(*svalue) : OptionalValue();
4062+}
4063+
4064+template <typename M>
4065+typename PersistentCache<std::string, std::string, M>::OptionalData
4066+ PersistentCache<std::string, std::string, M>::take_data(std::string const& key)
4067+{
4068+ auto sdata = p_->take_data(key);
4069+ if (!sdata)
4070+ {
4071+ return OptionalData();
4072+ }
4073+ return OptionalData({sdata->value, CacheCodec<M>::decode(sdata->metadata)});
4074+}
4075+
4076+template <typename M>
4077+bool PersistentCache<std::string, std::string, M>::invalidate(std::string const& key)
4078+{
4079+ return p_->invalidate(key);
4080+}
4081+
4082+template <typename M>
4083+void PersistentCache<std::string, std::string, M>::invalidate(std::vector<std::string> const& keys)
4084+{
4085+ invalidate(keys.begin(), keys.end());
4086+}
4087+
4088+template <typename M>
4089+template <typename It>
4090+void PersistentCache<std::string, std::string, M>::invalidate(It begin, It end)
4091+{
4092+ std::vector<std::string> skeys;
4093+ for (auto&& it = begin; it < end; ++it)
4094+ {
4095+ skeys.push_back(*it);
4096+ }
4097+ p_->invalidate(skeys.begin(), skeys.end());
4098+}
4099+
4100+template <typename M>
4101+void PersistentCache<std::string, std::string, M>::invalidate(std::initializer_list<std::string> const& keys)
4102+{
4103+ invalidate(keys.begin(), keys.end());
4104+}
4105+
4106+template <typename M>
4107+void PersistentCache<std::string, std::string, M>::invalidate()
4108+{
4109+ p_->invalidate();
4110+}
4111+
4112+template <typename M>
4113+bool PersistentCache<std::string, std::string, M>::touch(std::string const& key,
4114+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
4115+{
4116+ return p_->touch(key, expiry_time);
4117+}
4118+
4119+template <typename M>
4120+void PersistentCache<std::string, std::string, M>::clear_stats()
4121+{
4122+ p_->clear_stats();
4123+}
4124+
4125+template <typename M>
4126+void PersistentCache<std::string, std::string, M>::resize(int64_t size_in_bytes)
4127+{
4128+ p_->resize(size_in_bytes);
4129+}
4130+
4131+template <typename M>
4132+void PersistentCache<std::string, std::string, M>::trim_to(int64_t used_size_in_bytes)
4133+{
4134+ p_->trim_to(used_size_in_bytes);
4135+}
4136+
4137+template <typename M>
4138+void PersistentCache<std::string, std::string, M>::compact()
4139+{
4140+ p_->compact();
4141+}
4142+
4143+template <typename M>
4144+void PersistentCache<std::string, std::string, M>::set_handler(CacheEvent events, EventCallback cb)
4145+{
4146+ p_->set_handler(events, cb);
4147+}
4148+
4149+// Specialization for K and M = std::string.
4150+
4151+template <typename V>
4152+class PersistentCache<std::string, V, std::string>
4153+{
4154+public:
4155+ typedef std::unique_ptr<PersistentCache<std::string, V, std::string>> UPtr;
4156+
4157+ typedef Optional<std::string> OptionalKey;
4158+ typedef Optional<V> OptionalValue;
4159+ typedef Optional<std::string> OptionalMetadata;
4160+
4161+ struct Data
4162+ {
4163+ V value;
4164+ std::string metadata;
4165+ };
4166+ typedef Optional<Data> OptionalData;
4167+
4168+ PersistentCache(PersistentCache const&) = delete;
4169+ PersistentCache& operator=(PersistentCache const&) = delete;
4170+
4171+ PersistentCache(PersistentCache&&) = default;
4172+ PersistentCache& operator=(PersistentCache&&) = default;
4173+
4174+ ~PersistentCache() = default;
4175+
4176+ static UPtr open(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
4177+ static UPtr open(std::string const& cache_path);
4178+
4179+ OptionalValue get(std::string const& key) const;
4180+ OptionalData get_data(std::string const& key) const;
4181+ OptionalMetadata get_metadata(std::string const& key) const;
4182+ bool contains_key(std::string const& key) const;
4183+ int64_t size() const noexcept;
4184+ int64_t size_in_bytes() const noexcept;
4185+ int64_t max_size_in_bytes() const noexcept;
4186+ int64_t disk_size_in_bytes() const;
4187+ CacheDiscardPolicy discard_policy() const noexcept;
4188+ PersistentCacheStats stats() const;
4189+
4190+ bool put(std::string const& key,
4191+ V const& value,
4192+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4193+ bool put(std::string const& key,
4194+ V const& value,
4195+ std::string const& metadata,
4196+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4197+ bool put(std::string const& key,
4198+ V const& value,
4199+ char const* metadata,
4200+ int64_t size,
4201+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4202+
4203+ typedef std::function<void(std::string const& key, PersistentCache<std::string, V, std::string>& cache)> Loader;
4204+
4205+ OptionalValue get_or_put(std::string const& key, Loader const& load_func);
4206+ OptionalData get_or_put_data(std::string const& key, Loader const& load_func);
4207+
4208+ bool put_metadata(std::string const& key, std::string const& metadata);
4209+ bool put_metadata(std::string const& key, char const* metadata, int64_t size);
4210+ OptionalValue take(std::string const& key);
4211+ OptionalData take_data(std::string const& key);
4212+ bool invalidate(std::string const& key);
4213+ void invalidate(std::vector<std::string> const& keys);
4214+ template <typename It>
4215+ void invalidate(It begin, It end);
4216+ void invalidate(std::initializer_list<std::string> const& keys);
4217+ void invalidate();
4218+ bool touch(
4219+ std::string const& key,
4220+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4221+ void clear_stats();
4222+ void resize(int64_t size_in_bytes);
4223+ void trim_to(int64_t used_size_in_bytes);
4224+ void compact();
4225+
4226+ typedef std::function<void(std::string const& key, CacheEvent ev, PersistentCacheStats const& stats)> EventCallback;
4227+
4228+ void set_handler(CacheEvent events, EventCallback cb);
4229+
4230+private:
4231+ PersistentCache(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
4232+ PersistentCache(std::string const& cache_path);
4233+
4234+ std::unique_ptr<PersistentStringCache> p_;
4235+};
4236+
4237+template <typename V>
4238+PersistentCache<std::string, V, std::string>::PersistentCache(std::string const& cache_path,
4239+ int64_t max_size_in_bytes,
4240+ CacheDiscardPolicy policy)
4241+ : p_(PersistentStringCache::open(cache_path, max_size_in_bytes, policy))
4242+{
4243+}
4244+
4245+template <typename V>
4246+PersistentCache<std::string, V, std::string>::PersistentCache(std::string const& cache_path)
4247+ : p_(PersistentStringCache::open(cache_path))
4248+{
4249+}
4250+
4251+template <typename V>
4252+typename PersistentCache<std::string, V, std::string>::UPtr PersistentCache<std::string, V, std::string>::open(
4253+ std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy)
4254+{
4255+ return PersistentCache<std::string, V, std::string>::UPtr(
4256+ new PersistentCache<std::string, V, std::string>(cache_path, max_size_in_bytes, policy));
4257+}
4258+
4259+template <typename V>
4260+typename PersistentCache<std::string, V, std::string>::UPtr PersistentCache<std::string, V, std::string>::open(
4261+ std::string const& cache_path)
4262+{
4263+ return PersistentCache<std::string, V, std::string>::UPtr(
4264+ new PersistentCache<std::string, V, std::string>(cache_path));
4265+}
4266+
4267+template <typename V>
4268+typename PersistentCache<std::string, V, std::string>::OptionalValue PersistentCache<std::string, V, std::string>::get(
4269+ std::string const& key) const
4270+{
4271+ auto const& svalue = p_->get(key);
4272+ return svalue ? OptionalValue(CacheCodec<V>::decode(*svalue)) : OptionalValue();
4273+}
4274+
4275+template <typename V>
4276+typename PersistentCache<std::string, V, std::string>::OptionalData
4277+ PersistentCache<std::string, V, std::string>::get_data(std::string const& key) const
4278+{
4279+ auto sdata = p_->get_data(key);
4280+ if (!sdata)
4281+ {
4282+ return OptionalData();
4283+ }
4284+ return OptionalData({CacheCodec<V>::decode(sdata->value), sdata->metadata});
4285+}
4286+
4287+template <typename V>
4288+typename PersistentCache<std::string, V, std::string>::OptionalMetadata
4289+ PersistentCache<std::string, V, std::string>::get_metadata(std::string const& key) const
4290+{
4291+ auto smeta = p_->get_metadata(key);
4292+ return smeta ? OptionalMetadata(*smeta) : OptionalMetadata();
4293+}
4294+
4295+template <typename V>
4296+bool PersistentCache<std::string, V, std::string>::contains_key(std::string const& key) const
4297+{
4298+ return p_->contains_key(key);
4299+}
4300+
4301+template <typename V>
4302+int64_t PersistentCache<std::string, V, std::string>::size() const noexcept
4303+{
4304+ return p_->size();
4305+}
4306+
4307+template <typename V>
4308+int64_t PersistentCache<std::string, V, std::string>::size_in_bytes() const noexcept
4309+{
4310+ return p_->size_in_bytes();
4311+}
4312+
4313+template <typename V>
4314+int64_t PersistentCache<std::string, V, std::string>::max_size_in_bytes() const noexcept
4315+{
4316+ return p_->max_size_in_bytes();
4317+}
4318+
4319+template <typename V>
4320+int64_t PersistentCache<std::string, V, std::string>::disk_size_in_bytes() const
4321+{
4322+ return p_->disk_size_in_bytes();
4323+}
4324+
4325+template <typename V>
4326+CacheDiscardPolicy PersistentCache<std::string, V, std::string>::discard_policy() const noexcept
4327+{
4328+ return p_->discard_policy();
4329+}
4330+
4331+template <typename V>
4332+PersistentCacheStats PersistentCache<std::string, V, std::string>::stats() const
4333+{
4334+ return p_->stats();
4335+}
4336+
4337+template <typename V>
4338+bool PersistentCache<std::string, V, std::string>::put(std::string const& key,
4339+ V const& value,
4340+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
4341+{
4342+ return p_->put(key, CacheCodec<V>::encode(value), expiry_time);
4343+}
4344+
4345+template <typename V>
4346+bool PersistentCache<std::string, V, std::string>::put(std::string const& key,
4347+ V const& value,
4348+ std::string const& metadata,
4349+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
4350+{
4351+ std::string v = CacheCodec<V>::encode(value);
4352+ return p_->put(key, v.data(), v.size(), metadata.data(), metadata.size(), expiry_time);
4353+}
4354+
4355+template <typename V>
4356+bool PersistentCache<std::string, V, std::string>::put(std::string const& key,
4357+ V const& value,
4358+ char const* metadata,
4359+ int64_t size,
4360+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
4361+{
4362+ std::string v = CacheCodec<V>::encode(value);
4363+ return p_->put(key, v.data(), v.size(), metadata, size, expiry_time);
4364+}
4365+
4366+template <typename V>
4367+typename PersistentCache<std::string, V, std::string>::OptionalValue
4368+ PersistentCache<std::string, V, std::string>::get_or_put(
4369+ std::string const& key, PersistentCache<std::string, V, std::string>::Loader const& load_func)
4370+{
4371+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
4372+ {
4373+ load_func(key, *this);
4374+ };
4375+ auto svalue = p_->get_or_put(key, sload_func);
4376+ return svalue ? OptionalValue(CacheCodec<V>::decode(*svalue)) : OptionalValue();
4377+}
4378+
4379+template <typename V>
4380+typename PersistentCache<std::string, V, std::string>::OptionalData
4381+ PersistentCache<std::string, V, std::string>::get_or_put_data(
4382+ std::string const& key, PersistentCache<std::string, V, std::string>::Loader const& load_func)
4383+{
4384+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
4385+ {
4386+ load_func(key, *this);
4387+ };
4388+ auto sdata = p_->get_or_put_data(key, sload_func);
4389+ if (!sdata)
4390+ {
4391+ return OptionalData();
4392+ }
4393+ return OptionalData({CacheCodec<V>::decode(sdata->value), sdata->metadata});
4394+}
4395+
4396+template <typename V>
4397+bool PersistentCache<std::string, V, std::string>::put_metadata(std::string const& key, std::string const& metadata)
4398+{
4399+ return p_->put_metadata(key, metadata);
4400+}
4401+
4402+template <typename V>
4403+bool PersistentCache<std::string, V, std::string>::put_metadata(std::string const& key,
4404+ char const* metadata,
4405+ int64_t size)
4406+{
4407+ return p_->put_metadata(key, metadata, size);
4408+}
4409+
4410+template <typename V>
4411+typename PersistentCache<std::string, V, std::string>::OptionalValue PersistentCache<std::string, V, std::string>::take(
4412+ std::string const& key)
4413+{
4414+ auto svalue = p_->take(key);
4415+ return svalue ? OptionalValue(CacheCodec<V>::decode(*svalue)) : OptionalValue();
4416+}
4417+
4418+template <typename V>
4419+typename PersistentCache<std::string, V, std::string>::OptionalData
4420+ PersistentCache<std::string, V, std::string>::take_data(std::string const& key)
4421+{
4422+ auto sdata = p_->take_data(key);
4423+ if (!sdata)
4424+ {
4425+ return OptionalData();
4426+ }
4427+ return OptionalData({CacheCodec<V>::decode(sdata->value), sdata->metadata});
4428+}
4429+
4430+template <typename V>
4431+bool PersistentCache<std::string, V, std::string>::invalidate(std::string const& key)
4432+{
4433+ return p_->invalidate(key);
4434+}
4435+
4436+template <typename V>
4437+void PersistentCache<std::string, V, std::string>::invalidate(std::vector<std::string> const& keys)
4438+{
4439+ invalidate(keys.begin(), keys.end());
4440+}
4441+
4442+template <typename V>
4443+template <typename It>
4444+void PersistentCache<std::string, V, std::string>::invalidate(It begin, It end)
4445+{
4446+ std::vector<std::string> skeys;
4447+ for (auto&& it = begin; it < end; ++it)
4448+ {
4449+ skeys.push_back(*it);
4450+ }
4451+ p_->invalidate(skeys.begin(), skeys.end());
4452+}
4453+
4454+template <typename V>
4455+void PersistentCache<std::string, V, std::string>::invalidate(std::initializer_list<std::string> const& keys)
4456+{
4457+ invalidate(keys.begin(), keys.end());
4458+}
4459+
4460+template <typename V>
4461+void PersistentCache<std::string, V, std::string>::invalidate()
4462+{
4463+ p_->invalidate();
4464+}
4465+
4466+template <typename V>
4467+bool PersistentCache<std::string, V, std::string>::touch(std::string const& key,
4468+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
4469+{
4470+ return p_->touch(key, expiry_time);
4471+}
4472+
4473+template <typename V>
4474+void PersistentCache<std::string, V, std::string>::clear_stats()
4475+{
4476+ p_->clear_stats();
4477+}
4478+
4479+template <typename V>
4480+void PersistentCache<std::string, V, std::string>::resize(int64_t size_in_bytes)
4481+{
4482+ p_->resize(size_in_bytes);
4483+}
4484+
4485+template <typename V>
4486+void PersistentCache<std::string, V, std::string>::trim_to(int64_t used_size_in_bytes)
4487+{
4488+ p_->trim_to(used_size_in_bytes);
4489+}
4490+
4491+template <typename V>
4492+void PersistentCache<std::string, V, std::string>::compact()
4493+{
4494+ p_->compact();
4495+}
4496+
4497+template <typename V>
4498+void PersistentCache<std::string, V, std::string>::set_handler(CacheEvent events, EventCallback cb)
4499+{
4500+ p_->set_handler(events, cb);
4501+}
4502+
4503+// Specialization for V and M = std::string.
4504+
4505+template <typename K>
4506+class PersistentCache<K, std::string, std::string>
4507+{
4508+public:
4509+ typedef std::unique_ptr<PersistentCache<K, std::string, std::string>> UPtr;
4510+
4511+ typedef Optional<K> OptionalKey;
4512+ typedef Optional<std::string> OptionalValue;
4513+ typedef Optional<std::string> OptionalMetadata;
4514+
4515+ struct Data
4516+ {
4517+ std::string value;
4518+ std::string metadata;
4519+ };
4520+ typedef Optional<Data> OptionalData;
4521+
4522+ PersistentCache(PersistentCache const&) = delete;
4523+ PersistentCache& operator=(PersistentCache const&) = delete;
4524+
4525+ PersistentCache(PersistentCache&&) = default;
4526+ PersistentCache& operator=(PersistentCache&&) = default;
4527+
4528+ ~PersistentCache() = default;
4529+
4530+ static UPtr open(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
4531+ static UPtr open(std::string const& cache_path);
4532+
4533+ OptionalValue get(K const& key) const;
4534+ OptionalData get_data(K const& key) const;
4535+ OptionalMetadata get_metadata(K const& key) const;
4536+ bool contains_key(K const& key) const;
4537+ int64_t size() const noexcept;
4538+ int64_t size_in_bytes() const noexcept;
4539+ int64_t max_size_in_bytes() const noexcept;
4540+ int64_t disk_size_in_bytes() const;
4541+ CacheDiscardPolicy discard_policy() const noexcept;
4542+ PersistentCacheStats stats() const;
4543+
4544+ bool put(K const& key,
4545+ std::string const& value,
4546+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4547+ bool put(K const& key,
4548+ char const* value,
4549+ int64_t size,
4550+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4551+ bool put(K const& key,
4552+ std::string const& value,
4553+ std::string const& metadata,
4554+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4555+ bool put(K const& key,
4556+ char const* value,
4557+ int64_t value_size,
4558+ char const* metadata,
4559+ int64_t metadata_size,
4560+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4561+
4562+ typedef std::function<void(K const& key, PersistentCache<K, std::string, std::string>& cache)> Loader;
4563+
4564+ OptionalValue get_or_put(K const& key, Loader const& load_func);
4565+ OptionalData get_or_put_data(K const& key, Loader const& load_func);
4566+
4567+ bool put_metadata(K const& key, std::string const& metadata);
4568+ bool put_metadata(K const& key, char const* metadata, int64_t size);
4569+ OptionalValue take(K const& key);
4570+ OptionalData take_data(K const& key);
4571+ bool invalidate(K const& key);
4572+ void invalidate(std::vector<K> const& keys);
4573+ template <typename It>
4574+ void invalidate(It begin, It end);
4575+ void invalidate(std::initializer_list<K> const& keys);
4576+ void invalidate();
4577+ bool touch(
4578+ K const& key,
4579+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4580+ void clear_stats();
4581+ void resize(int64_t size_in_bytes);
4582+ void trim_to(int64_t used_size_in_bytes);
4583+ void compact();
4584+
4585+ typedef std::function<void(K const& key, CacheEvent ev, PersistentCacheStats const& stats)> EventCallback;
4586+
4587+ void set_handler(CacheEvent events, EventCallback cb);
4588+
4589+private:
4590+ PersistentCache(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
4591+ PersistentCache(std::string const& cache_path);
4592+
4593+ std::unique_ptr<PersistentStringCache> p_;
4594+};
4595+
4596+template <typename K>
4597+PersistentCache<K, std::string, std::string>::PersistentCache(std::string const& cache_path,
4598+ int64_t max_size_in_bytes,
4599+ CacheDiscardPolicy policy)
4600+ : p_(PersistentStringCache::open(cache_path, max_size_in_bytes, policy))
4601+{
4602+}
4603+
4604+template <typename K>
4605+PersistentCache<K, std::string, std::string>::PersistentCache(std::string const& cache_path)
4606+ : p_(PersistentStringCache::open(cache_path))
4607+{
4608+}
4609+
4610+template <typename K>
4611+typename PersistentCache<K, std::string, std::string>::UPtr PersistentCache<K, std::string, std::string>::open(
4612+ std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy)
4613+{
4614+ return PersistentCache<K, std::string, std::string>::UPtr(
4615+ new PersistentCache<K, std::string, std::string>(cache_path, max_size_in_bytes, policy));
4616+}
4617+
4618+template <typename K>
4619+typename PersistentCache<K, std::string, std::string>::UPtr PersistentCache<K, std::string, std::string>::open(
4620+ std::string const& cache_path)
4621+{
4622+ return PersistentCache<K, std::string, std::string>::UPtr(
4623+ new PersistentCache<K, std::string, std::string>(cache_path));
4624+}
4625+
4626+template <typename K>
4627+typename PersistentCache<K, std::string, std::string>::OptionalValue PersistentCache<K, std::string, std::string>::get(
4628+ K const& key) const
4629+{
4630+ auto const& svalue = p_->get(CacheCodec<K>::encode(key));
4631+ return svalue ? OptionalValue(*svalue) : OptionalValue();
4632+}
4633+
4634+template <typename K>
4635+typename PersistentCache<K, std::string, std::string>::OptionalData
4636+ PersistentCache<K, std::string, std::string>::get_data(K const& key) const
4637+{
4638+ auto sdata = p_->get_data(CacheCodec<K>::encode(key));
4639+ if (!sdata)
4640+ {
4641+ return OptionalData();
4642+ }
4643+ return OptionalData({sdata->value, sdata->metadata});
4644+}
4645+
4646+template <typename K>
4647+typename PersistentCache<K, std::string, std::string>::OptionalMetadata
4648+ PersistentCache<K, std::string, std::string>::get_metadata(K const& key) const
4649+{
4650+ auto smeta = p_->get_metadata(CacheCodec<K>::encode(key));
4651+ return smeta ? OptionalMetadata(*smeta) : OptionalMetadata();
4652+}
4653+
4654+template <typename K>
4655+bool PersistentCache<K, std::string, std::string>::contains_key(K const& key) const
4656+{
4657+ return p_->contains_key(CacheCodec<K>::encode(key));
4658+}
4659+
4660+template <typename K>
4661+int64_t PersistentCache<K, std::string, std::string>::size() const noexcept
4662+{
4663+ return p_->size();
4664+}
4665+
4666+template <typename K>
4667+int64_t PersistentCache<K, std::string, std::string>::size_in_bytes() const noexcept
4668+{
4669+ return p_->size_in_bytes();
4670+}
4671+
4672+template <typename K>
4673+int64_t PersistentCache<K, std::string, std::string>::max_size_in_bytes() const noexcept
4674+{
4675+ return p_->max_size_in_bytes();
4676+}
4677+
4678+template <typename K>
4679+int64_t PersistentCache<K, std::string, std::string>::disk_size_in_bytes() const
4680+{
4681+ return p_->disk_size_in_bytes();
4682+}
4683+
4684+template <typename K>
4685+CacheDiscardPolicy PersistentCache<K, std::string, std::string>::discard_policy() const noexcept
4686+{
4687+ return p_->discard_policy();
4688+}
4689+
4690+template <typename K>
4691+PersistentCacheStats PersistentCache<K, std::string, std::string>::stats() const
4692+{
4693+ return p_->stats();
4694+}
4695+
4696+template <typename K>
4697+bool PersistentCache<K, std::string, std::string>::put(K const& key,
4698+ std::string const& value,
4699+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
4700+{
4701+ return p_->put(CacheCodec<K>::encode(key), value, expiry_time);
4702+}
4703+
4704+template <typename K>
4705+bool PersistentCache<K, std::string, std::string>::put(K const& key,
4706+ char const* value,
4707+ int64_t size,
4708+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
4709+{
4710+ return p_->put(CacheCodec<K>::encode(key), value, size, expiry_time);
4711+}
4712+
4713+template <typename K>
4714+bool PersistentCache<K, std::string, std::string>::put(K const& key,
4715+ std::string const& value,
4716+ std::string const& metadata,
4717+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
4718+{
4719+ return p_->put(CacheCodec<K>::encode(key), value, metadata, expiry_time);
4720+}
4721+
4722+template <typename K>
4723+bool PersistentCache<K, std::string, std::string>::put(K const& key,
4724+ char const* value,
4725+ int64_t value_size,
4726+ char const* metadata,
4727+ int64_t metadata_size,
4728+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
4729+{
4730+ return p_->put(CacheCodec<K>::encode(key), value, value_size, metadata, metadata_size, expiry_time);
4731+}
4732+
4733+template <typename K>
4734+typename PersistentCache<K, std::string, std::string>::OptionalValue
4735+ PersistentCache<K, std::string, std::string>::get_or_put(
4736+ K const& key, PersistentCache<K, std::string, std::string>::Loader const& load_func)
4737+{
4738+ auto skey = CacheCodec<K>::encode(key);
4739+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
4740+ {
4741+ load_func(key, *this);
4742+ };
4743+ auto svalue = p_->get_or_put(skey, sload_func);
4744+ return svalue ? OptionalValue(*svalue) : OptionalValue();
4745+}
4746+
4747+template <typename K>
4748+typename PersistentCache<K, std::string, std::string>::OptionalData
4749+ PersistentCache<K, std::string, std::string>::get_or_put_data(
4750+ K const& key, PersistentCache<K, std::string, std::string>::Loader const& load_func)
4751+{
4752+ auto skey = CacheCodec<K>::encode(key);
4753+ auto sload_func = [&](std::string const&, PersistentStringCache const&)
4754+ {
4755+ load_func(key, *this);
4756+ };
4757+ auto sdata = p_->get_or_put_data(skey, sload_func);
4758+ if (!sdata)
4759+ {
4760+ return OptionalData();
4761+ }
4762+ return OptionalData({sdata->value, sdata->metadata});
4763+}
4764+
4765+template <typename K>
4766+bool PersistentCache<K, std::string, std::string>::put_metadata(K const& key, std::string const& metadata)
4767+{
4768+ return p_->put_metadata(CacheCodec<K>::encode(key), metadata);
4769+}
4770+
4771+template <typename K>
4772+bool PersistentCache<K, std::string, std::string>::put_metadata(K const& key, char const* metadata, int64_t size)
4773+{
4774+ return p_->put_metadata(CacheCodec<K>::encode(key), metadata, size);
4775+}
4776+
4777+template <typename K>
4778+typename PersistentCache<K, std::string, std::string>::OptionalValue PersistentCache<K, std::string, std::string>::take(
4779+ K const& key)
4780+{
4781+ auto svalue = p_->take(CacheCodec<K>::encode(key));
4782+ return svalue ? OptionalValue(*svalue) : OptionalValue();
4783+}
4784+
4785+template <typename K>
4786+typename PersistentCache<K, std::string, std::string>::OptionalData
4787+ PersistentCache<K, std::string, std::string>::take_data(K const& key)
4788+{
4789+ auto sdata = p_->take_data(CacheCodec<K>::encode(key));
4790+ if (!sdata)
4791+ {
4792+ return OptionalData();
4793+ }
4794+ return OptionalData({sdata->value, sdata->metadata});
4795+}
4796+
4797+template <typename K>
4798+bool PersistentCache<K, std::string, std::string>::invalidate(K const& key)
4799+{
4800+ return p_->invalidate(CacheCodec<K>::encode(key));
4801+}
4802+
4803+template <typename K>
4804+void PersistentCache<K, std::string, std::string>::invalidate(std::vector<K> const& keys)
4805+{
4806+ invalidate(keys.begin(), keys.end());
4807+}
4808+
4809+template <typename K>
4810+template <typename It>
4811+void PersistentCache<K, std::string, std::string>::invalidate(It begin, It end)
4812+{
4813+ std::vector<std::string> skeys;
4814+ for (auto&& it = begin; it < end; ++it)
4815+ {
4816+ skeys.push_back(CacheCodec<K>::encode(*it));
4817+ }
4818+ p_->invalidate(skeys.begin(), skeys.end());
4819+}
4820+
4821+template <typename K>
4822+void PersistentCache<K, std::string, std::string>::invalidate(std::initializer_list<K> const& keys)
4823+{
4824+ invalidate(keys.begin(), keys.end());
4825+}
4826+
4827+template <typename K>
4828+void PersistentCache<K, std::string, std::string>::invalidate()
4829+{
4830+ p_->invalidate();
4831+}
4832+
4833+template <typename K>
4834+bool PersistentCache<K, std::string, std::string>::touch(K const& key,
4835+ std::chrono::time_point<std::chrono::system_clock> expiry_time)
4836+{
4837+ return p_->touch(CacheCodec<K>::encode(key), expiry_time);
4838+}
4839+
4840+template <typename K>
4841+void PersistentCache<K, std::string, std::string>::clear_stats()
4842+{
4843+ p_->clear_stats();
4844+}
4845+
4846+template <typename K>
4847+void PersistentCache<K, std::string, std::string>::resize(int64_t size_in_bytes)
4848+{
4849+ p_->resize(size_in_bytes);
4850+}
4851+
4852+template <typename K>
4853+void PersistentCache<K, std::string, std::string>::trim_to(int64_t used_size_in_bytes)
4854+{
4855+ p_->trim_to(used_size_in_bytes);
4856+}
4857+
4858+template <typename K>
4859+void PersistentCache<K, std::string, std::string>::compact()
4860+{
4861+ p_->compact();
4862+}
4863+
4864+template <typename K>
4865+void PersistentCache<K, std::string, std::string>::set_handler(CacheEvent events, EventCallback cb)
4866+{
4867+ auto scb = [cb](std::string const& key, CacheEvent ev, PersistentCacheStats const& c)
4868+ {
4869+ cb(CacheCodec<K>::decode(key), ev, c);
4870+ };
4871+ p_->set_handler(events, scb);
4872+}
4873+
4874+// Specialization for K, V, and M = std::string.
4875+
4876+template <>
4877+class PersistentCache<std::string, std::string, std::string>
4878+{
4879+public:
4880+ typedef std::unique_ptr<PersistentCache<std::string, std::string, std::string>> UPtr;
4881+
4882+ typedef Optional<std::string> OptionalKey;
4883+ typedef Optional<std::string> OptionalValue;
4884+ typedef Optional<std::string> OptionalMetadata;
4885+
4886+ struct Data
4887+ {
4888+ std::string value;
4889+ std::string metadata;
4890+ };
4891+ typedef Optional<Data> OptionalData;
4892+
4893+ PersistentCache(PersistentCache const&) = delete;
4894+ PersistentCache& operator=(PersistentCache const&) = delete;
4895+
4896+ PersistentCache(PersistentCache&&) = default;
4897+ PersistentCache& operator=(PersistentCache&&) = default;
4898+
4899+ ~PersistentCache() = default;
4900+
4901+ static UPtr open(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
4902+ static UPtr open(std::string const& cache_path);
4903+
4904+ OptionalValue get(std::string const& key) const;
4905+ OptionalData get_data(std::string const& key) const;
4906+ OptionalMetadata get_metadata(std::string const& key) const;
4907+ bool contains_key(std::string const& key) const;
4908+ int64_t size() const noexcept;
4909+ int64_t size_in_bytes() const noexcept;
4910+ int64_t max_size_in_bytes() const noexcept;
4911+ int64_t disk_size_in_bytes() const;
4912+ CacheDiscardPolicy discard_policy() const noexcept;
4913+ PersistentCacheStats stats() const;
4914+
4915+ bool put(std::string const& key,
4916+ std::string const& value,
4917+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4918+ bool put(std::string const& key,
4919+ char const* value,
4920+ int64_t size,
4921+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4922+ bool put(std::string const& key,
4923+ std::string const& value,
4924+ std::string const& metadata,
4925+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4926+ bool put(std::string const& key,
4927+ char const* value,
4928+ int64_t value_size,
4929+ char const* metadata,
4930+ int64_t metadata_size,
4931+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4932+
4933+ typedef std::function<void(std::string const& key, PersistentCache<std::string, std::string, std::string>& cache)>
4934+ Loader;
4935+
4936+ OptionalValue get_or_put(std::string const& key, Loader const& load_func);
4937+ OptionalData get_or_put_data(std::string const& key, Loader const& load_func);
4938+
4939+ bool put_metadata(std::string const& key, std::string const& metadata);
4940+ bool put_metadata(std::string const& key, char const* metadata, int64_t size);
4941+ OptionalValue take(std::string const& key);
4942+ OptionalData take_data(std::string const& key);
4943+ bool invalidate(std::string const& key);
4944+ void invalidate(std::vector<std::string> const& keys);
4945+ template <typename It>
4946+ void invalidate(It begin, It end);
4947+ void invalidate(std::initializer_list<std::string> const& keys);
4948+ void invalidate();
4949+ bool touch(
4950+ std::string const& key,
4951+ std::chrono::time_point<std::chrono::system_clock> expiry_time = std::chrono::system_clock::time_point());
4952+ void clear_stats();
4953+ void resize(int64_t size_in_bytes);
4954+ void trim_to(int64_t used_size_in_bytes);
4955+ void compact();
4956+
4957+ typedef std::function<void(std::string const& key, CacheEvent ev, PersistentCacheStats const& stats)> EventCallback;
4958+
4959+ void set_handler(CacheEvent events, EventCallback cb);
4960+
4961+private:
4962+ PersistentCache(std::string const& cache_path, int64_t max_size_in_bytes, CacheDiscardPolicy policy);
4963+ PersistentCache(std::string const& cache_path);
4964+
4965+ std::unique_ptr<PersistentStringCache> p_;
4966+};
4967+
4968+PersistentCache<std::string, std::string, std::string>::PersistentCache(std::string const& cache_path,
4969+ int64_t max_size_in_bytes,
4970+ CacheDiscardPolicy policy)
4971+ : p_(PersistentStringCache::open(cache_path, max_size_in_bytes, policy))
4972+{
4973+}
4974+
4975+PersistentCache<std::string, std::string, std::string>::PersistentCache(std::string const& cache_path)
4976+ : p_(PersistentStringCache::open(cache_path))
4977+{
4978+}
4979+
4980+typename PersistentCache<std::string, std::string, std::string>::UPtr
4981+ PersistentCache<std::string, std::string, std::string>::open(std::string const& cache_path,
4982+ int64_t max_size_in_bytes,
4983+ CacheDiscardPolicy policy)
4984+{
4985+ return PersistentCache<std::string, std::string, std::string>::UPtr(
4986+ new PersistentCache<std::string, std::string, std::string>(cache_path, max_size_in_bytes, policy));
4987+}
4988+
4989+typename PersistentCache<std::string, std::string, std::string>::UPtr
4990+ PersistentCache<std::string, std::string, std::string>::open(std::string const& cache_path)
4991+{
4992+ return PersistentCache<std::string, std::string, std::string>::UPtr(
4993+ new PersistentCache<std::string, std::string, std::string>(cache_path));
4994+}
4995+
4996+typename PersistentCache<std::string, std::string, std::string>::OptionalValue
4997+ PersistentCache<std::string, std::string, std::string>::get(std::string const& key) const
4998+{
4999+ auto const& svalue = p_->get(key);
5000+ return svalue ? OptionalValue(*svalue) : OptionalValue();
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to all changes: