| 1168 | // --------------------------------------------------------------------------- |
| 1169 | |
| 1170 | bool NetworkFilePropertiesCache::tryGet(PJ_CONTEXT *ctx, const std::string &url, |
| 1171 | FileProperties &props) { |
| 1172 | if (cache_.tryGet(url, props)) { |
| 1173 | return true; |
| 1174 | } |
| 1175 | |
| 1176 | auto diskCache = DiskChunkCache::open(ctx); |
| 1177 | if (!diskCache) |
| 1178 | return false; |
| 1179 | auto stmt = |
| 1180 | diskCache->prepare("SELECT lastChecked, fileSize, lastModified, etag " |
| 1181 | "FROM properties WHERE url = ?"); |
| 1182 | if (!stmt) |
| 1183 | return false; |
| 1184 | stmt->bindText(url.c_str()); |
| 1185 | if (stmt->execute() != SQLITE_ROW) { |
| 1186 | return false; |
| 1187 | } |
| 1188 | props.lastChecked = stmt->getInt64(); |
| 1189 | props.size = stmt->getInt64(); |
| 1190 | const char *lastModified = stmt->getText(); |
| 1191 | props.lastModified = lastModified ? lastModified : std::string(); |
| 1192 | const char *etag = stmt->getText(); |
| 1193 | props.etag = etag ? etag : std::string(); |
| 1194 | |
| 1195 | const auto ttl = pj_context_get_grid_cache_ttl(ctx); |
| 1196 | if (ttl > 0) { |
| 1197 | time_t curTime; |
| 1198 | time(&curTime); |
| 1199 | if (curTime > props.lastChecked + ttl) { |
| 1200 | props = FileProperties(); |
| 1201 | return false; |
| 1202 | } |
| 1203 | } |
| 1204 | cache_.insert(url, props); |
| 1205 | return true; |
| 1206 | } |
| 1207 | |
| 1208 | // --------------------------------------------------------------------------- |
| 1209 |
no test coverage detected