Skip to content

Commit 00d8220

Browse files
authored
Merge pull request #919 from lonvia/allow-diasble-node-cache
Allow to truely disable the RAM node cache
2 parents cf0208d + ed88977 commit 00d8220

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

node-ram-cache.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ node_ram_cache::node_ram_cache(int strategy, int cacheSizeMB)
316316
cacheSize((int64_t)cacheSizeMB * 1024 * 1024), storedNodes(0), totalNodes(0),
317317
nodesCacheHits(0), nodesCacheLookups(0), warn_node_order(0)
318318
{
319+
if (cacheSize == 0)
320+
return;
321+
319322
blockCache = 0;
320323
blockCachePos = 0;
321324
/* How much we can fit, and make sure it's odd */
@@ -388,6 +391,9 @@ node_ram_cache::node_ram_cache(int strategy, int cacheSizeMB)
388391

389392
node_ram_cache::~node_ram_cache()
390393
{
394+
if (cacheSize == 0)
395+
return;
396+
391397
fprintf(stderr, "node cache: stored: %" PRIdOSMID
392398
"(%.2f%%), storage efficiency: %.2f%% (dense blocks: %i, "
393399
"sparse nodes: %" PRId64 "), hit rate: %.2f%%\n",
@@ -417,6 +423,9 @@ node_ram_cache::~node_ram_cache()
417423

418424
void node_ram_cache::set(osmid_t id, const osmium::Location &coord)
419425
{
426+
if (cacheSize == 0)
427+
return;
428+
420429
if ((id > 0 && id >> BLOCK_SHIFT >> 32) ||
421430
(id < 0 && ~id >> BLOCK_SHIFT >> 32)) {
422431
fprintf(stderr, "\nAbsolute node IDs must not be larger than %" PRId64
@@ -448,6 +457,9 @@ osmium::Location node_ram_cache::get(osmid_t id)
448457
{
449458
osmium::Location coord;
450459

460+
if (cacheSize == 0)
461+
return coord;
462+
451463
if (allocStrategy & ALLOC_DENSE) {
452464
coord = get_dense(id);
453465
}

options.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,14 @@ void options_t::check_options()
592592
}
593593

594594
if (cache == 0) {
595-
fprintf(stderr, "WARNING: ram cache is disabled. This will likely slow down processing a lot.\n\n");
595+
if (!slim) {
596+
throw std::runtime_error(
597+
"Ram node cache can only be disable in slim mode.\n");
598+
}
599+
if (!flat_node_cache_enabled) {
600+
fprintf(stderr, "WARNING: ram cache is disabled. This will likely "
601+
"slow down processing a lot.\n\n");
602+
}
596603
}
597604

598605
if (num_procs < 1) {

0 commit comments

Comments
 (0)