MCPcopy Create free account
hub / github.com/OSGeo/PROJ / tryGet

Method tryGet

src/networkfilemanager.cpp:1192–1228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1190// ---------------------------------------------------------------------------
1191
1192bool 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

Callers 7

getMethod · 0.45
getHandleMethod · 0.45
getFromCacheMethod · 0.45
getGridInfoFromCacheMethod · 0.45
getAliasesMethod · 0.45
getNameMethod · 0.45

Calls 8

FilePropertiesClass · 0.85
bindTextMethod · 0.80
getInt64Method · 0.80
getTextMethod · 0.80
prepareMethod · 0.45
executeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected