| 1190 | // --------------------------------------------------------------------------- |
| 1191 | |
| 1192 | bool NetworkFilePropertiesCache::tryGet(PJ_CONTEXT *ctx, const std::string &url, |
| 1193 | FileProperties &props) { |
| 1194 | if (cache_.tryGet(url, props)) { |
| 1195 | return true; |
| 1196 | } |
| 1197 | |
| 1198 | auto diskCache = DiskChunkCache::open(ctx); |
| 1199 | if (!diskCache) |
| 1200 | return false; |
| 1201 | auto stmt = |
| 1202 | diskCache->prepare("SELECT lastChecked, fileSize, lastModified, etag " |
| 1203 | "FROM properties WHERE url = ?"); |
| 1204 | if (!stmt) |
| 1205 | return false; |
| 1206 | stmt->bindText(url.c_str()); |
| 1207 | if (stmt->execute() != SQLITE_ROW) { |
| 1208 | return false; |
| 1209 | } |
| 1210 | props.lastChecked = static_cast<time_t>(stmt->getInt64()); |
| 1211 | props.size = stmt->getInt64(); |
| 1212 | const char *lastModified = stmt->getText(); |
| 1213 | props.lastModified = lastModified ? lastModified : std::string(); |
| 1214 | const char *etag = stmt->getText(); |
| 1215 | props.etag = etag ? etag : std::string(); |
| 1216 | |
| 1217 | const auto ttl = pj_context_get_grid_cache_ttl(ctx); |
| 1218 | if (ttl > 0) { |
| 1219 | time_t curTime; |
| 1220 | time(&curTime); |
| 1221 | if (curTime > props.lastChecked + ttl) { |
| 1222 | props = FileProperties(); |
| 1223 | return false; |
| 1224 | } |
| 1225 | } |
| 1226 | cache_.insert(url, props); |
| 1227 | return true; |
| 1228 | } |
| 1229 | |
| 1230 | // --------------------------------------------------------------------------- |
| 1231 |
no test coverage detected