geocoder-php/cache-provider

缓存提供商的结果

4.4.0 2022-07-30 12:09 UTC

This package is auto-updated.

Last update: 2024-09-04 10:56:42 UTC


README

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

这是PHP Geocoder的一个缓存提供商。这是一个只读仓库。有关信息和文档,请参阅主仓库

安装

composer require geocoder-php/cache-provider

用法

ProviderCache 允许您使用任何PSR-6 兼容的缓存驱动程序。您可以在packagist上找到兼容的驱动程序。

默认情况下,结果将永久缓存。您可以通过传递表示秒数的整数作为第三个参数来设置缓存过期时间。

$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'));

贡献

欢迎贡献!请向主仓库发送拉取请求或报告您发现的问题问题追踪器