You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-1Lines changed: 23 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -190,7 +190,9 @@ Caching
190
190
191
191
Caching is available at the connector level if the connector implements `CacheToggle`. Connectors typically extend `CachingConnector` which implements [PSR-6][PSR-6]-compatible caching. Porter ships with just one cache implementation, `MemoryCache`, which stores data in memory but this can be substituted for any PSR-6 cache if the connector permits it.
192
192
193
-
When available, the connector caches raw responses for each unique cache key. The cache key is comprised of the source and options parameters passed to `Connector::fetch`. Options are sorted before the cache key is created so the order of options are insignificant.
193
+
When available, the connector caches raw responses for each unique [cache key](#cache-key). Cache keys are generated by an implementation-defined strategy or the default `JsonCacheKeyGenerator` strategy.
194
+
195
+
### Cache advice
194
196
195
197
Caching behaviour is specified by one of the `CacheAdvice` enumeration constants listed below.
196
198
@@ -212,6 +214,26 @@ $records = $porter->import(
212
214
);
213
215
```
214
216
217
+
### Cache key
218
+
219
+
The cache key can optionally be generated by an implementation of `CacheKeyGeneratorInterface` if the connector permits it. This implementation should provide one method `generateCacheKey` which returns a [PSR-6][PSR-6]-compatible cache key.
220
+
221
+
The default implementation `JsonCacheKeyGenerator` generates keys comprised of the source and options parameters passed to `Connector::fetch`. Options are sorted before the cache key is created so the order of options are insignificant.
222
+
223
+
#### Implementation example
224
+
225
+
The following example demonstrates a simple cache key generation implementation using an md5 hash of the json encoded parameters.
226
+
227
+
```php
228
+
class MyCacheKeyGenerator implements CacheKeyGenerator
229
+
{
230
+
public function generateCacheKey($source, array $sortedOptions)
0 commit comments