geocoder-php / geocoder-php/Geocoder

Improve ProviderCache

Open
#904 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
PHP
Stars
4k
Forks
525
Avg merge
8m
Merged PRs (30d)
1

Description

What are you think about add to ProviderCache flag isAllowEmptyResult?

For example:

$chain = new \Geocoder\Provider\Chain\Chain([
    // ...
]);
$cache = new \Geocoder\Provider\Cache\ProviderCache($chain, $cache, 86400);

When have exceptions from providers the chain catch and return empty ArrayCollection.
This result is saved for 24h. I think will be good point if I don't save empty results.

https://github.com/geocoder-php/Geocoder/blob/35650985d8b69ead88340ca5b75546f7117fad06/src/Provider/Cache/ProviderCache.php#L65-L66

Here is example how I think can be:

         $result = $this->realProvider->geocodeQuery($query); 
         if (!$result->isEmpty() || $this->isAllowEmptyResult)) {
             $this->cache->set($cacheKey, $result, $this->lifetime);
         }

What are you think about it?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/Provider/Cache/ProviderCache.php, especially the cache write around lines 65–66, and trace how Chain returns an empty ArrayCollection after provider exceptions. Define how the proposed isAllowEmptyResult option should affect caching, then verify that empty results are skipped by default and stored when the option permits them.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.