geocoder-php/cache-provider

Cache the result of a provider

Package info

github.com/geocoder-php/cache-provider

Homepage

pkg:composer/geocoder-php/cache-provider

Statistics

Installs: 1 547 235

Dependents: 9

Suggesters: 0

Stars: 7

4.5.0 2025-04-15 13:24 UTC

Requires

Requires (Dev)

Suggests

None

Conflicts

None

Replaces

None

MIT 3b091778426722cf96e166d187bbdd28660635b8

  • Tobias Nyholm <tobias.nyholm.woop@gmail.com>

This package is auto-updated.

Last update: 2026-06-21 12:45:51 UTC


README

👁 Build Status
👁 Latest Stable Version
👁 Total Downloads
👁 Monthly Downloads
👁 Code Coverage
👁 Quality Score
👁 Software License

This is the a cache provider from the PHP Geocoder. This is a READ ONLY repository. See the main repo for information and documentation.

Install

composer require geocoder-php/cache-provider

Usage

The ProviderCache allows you to use any PSR-6 compatible cache driver. You can find compatible drivers on packagist.

By default, the result is cached forever. You can set a cache expiry by passing an integer representing the number of seconds as the third parameter.

$httpClient = new \Http\Discovery\Psr18Client();
$provider = new \Geocoder\Provider\GoogleMaps\GoogleMaps($httpClient);

$psr6Cache = new ArrayCachePool(); // Requires `cache/array-adapter` package

$cachedProvider = new \Geocoder\Provider\Cache\ProviderCache(
 $provider, // Provider to cache
 $psr6Cache, // PSR-6 compatible cache
 600 // Cache expiry, in seconds
);

$geocoder = new \Geocoder\StatefulGeocoder($cachedProvider, 'en');

// Will come from Google Maps API
$result1 = $geocoder->geocodeQuery(GeocodeQuery::create('Buckingham Palace, London'));
// Will come from the cache
$result2 = $geocoder->geocodeQuery(GeocodeQuery::create('Buckingham Palace, London'));

Contribute

Contributions are very welcome! Send a pull request to the main repository or report any issues you find on the issue tracker.