@@ -67,7 +67,7 @@ void UnqliteHandleResult(std::string operation, unqlite* database, int ret) {
67
67
// Storing index+content in an unqlite database (possibly shared between
68
68
// multiple cquery caches, since it could be a user-setting)
69
69
struct UnqliteCacheDriver : public ICacheStore {
70
- UnqliteCacheDriver (unqlite* database) : database_(database) {}
70
+ UnqliteCacheDriver (unqlite* database) : database_(database), bytesSinceCommit_( 0 ) {}
71
71
72
72
UnqliteCacheDriver (UnqliteCacheDriver&) = delete ;
73
73
@@ -84,9 +84,15 @@ struct UnqliteCacheDriver : public ICacheStore {
84
84
}
85
85
86
86
if (ret == UNQLITE_OK)
87
+ {
88
+ LOG_S (INFO) << " unqlite: Handing out cache for key \" " << key << " \" " ;
87
89
return std::move (result);
90
+ }
88
91
else
92
+ {
93
+ LOG_S (WARNING) << " unqlite: No data for key \" " << key << " \" " ;
89
94
return {};
95
+ }
90
96
}
91
97
92
98
void Write (const std::string& key, const std::string& value) override {
@@ -97,6 +103,16 @@ struct UnqliteCacheDriver : public ICacheStore {
97
103
if (ret != UNQLITE_OK) {
98
104
UnqliteHandleResult (" unqlite_kv_store" , database_, ret);
99
105
}
106
+ else
107
+ {
108
+ bytesSinceCommit_ += value.size ();
109
+
110
+ if (bytesSinceCommit_ > 32 *1024 *1024 )
111
+ {
112
+ ret = unqlite_commit (database_);
113
+ if (ret == UNQLITE_OK) bytesSinceCommit_ = 0u ;
114
+ }
115
+ }
100
116
}
101
117
102
118
void Close () override {
@@ -112,6 +128,7 @@ struct UnqliteCacheDriver : public ICacheStore {
112
128
113
129
~UnqliteCacheDriver () override {}
114
130
131
+ size_t bytesSinceCommit_;
115
132
unqlite* database_;
116
133
};
117
134
@@ -141,6 +158,10 @@ IndexFile* IndexCache::TryLoad(const NormalizedPath& path) {
141
158
result = ptr.get ();
142
159
caches_.emplace (path.path , std::move (ptr));
143
160
}
161
+ else
162
+ {
163
+ LOG_S (WARNING) << " IndexCache::TryLoad: Cannot serve cache request for \" " << path.path << " \" " ;
164
+ }
144
165
145
166
return result;
146
167
}
@@ -159,12 +180,15 @@ optional<std::string> IndexCache::TryLoadContent(const NormalizedPath& path) {
159
180
160
181
std::unique_ptr<IndexFile> IndexCache::LoadIndexFileFromCache (
161
182
const NormalizedPath& file) {
162
- optional<std::string> file_content = ReadContent (file.path );
163
- optional<std::string> serialized_indexed_content = ReadContent (
183
+ optional<std::string> file_content = driver_-> Read (file.path );
184
+ optional<std::string> serialized_indexed_content = driver_-> Read (
164
185
file.path + SerializationFormatToSuffix (g_config->cacheFormat ));
165
186
166
187
if (!file_content || !serialized_indexed_content)
188
+ {
189
+ LOG_S (WARNING) << " IndexCache::LoadIndexFileFromCache: Cannot serve cache request for \" " << file.path << " \" " ;
167
190
return nullptr ;
191
+ }
168
192
169
193
return Deserialize (g_config->cacheFormat , file.path ,
170
194
*serialized_indexed_content, *file_content,
@@ -222,8 +246,6 @@ std::shared_ptr<ICacheStore> OpenOrConnectUnqliteStore(
222
246
LOG_S (WARNING) << " Unqlite: unqlite_open reported error condition " << ret
223
247
<< " ." ;
224
248
225
- ret = unqlite_config (database, UNQLITE_CONFIG_MAX_PAGE_CACHE, 64 *1024 );
226
-
227
249
// if (ret == UNQLITE_OK) return
228
250
// std::make_shared<UnqliteCacheDriver>(database);
229
251
if (ret == UNQLITE_OK)
0 commit comments