From 7bc8ba6343297d7cf91867a10f71c3611cf5b9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 26 Jun 2019 21:40:13 +0200 Subject: [PATCH] Documentation for TTL precision with millisecond accuracy or below --- README.md | 8 ++++++++ src/CacheInterface.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 3feef7f..311d829 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,14 @@ $cache->set('foo', 'bar', 60); This example eventually sets the value of the key `foo` to `bar`. If it already exists, it is overridden. +This interface does not enforce any particular TTL resolution, so special +care may have to be taken if you rely on very high precision with +millisecond accuracy or below. Cache implementations SHOULD work on a +best effort basis and SHOULD provide at least second accuracy unless +otherwise noted. Many existing cache implementations are known to provide +microsecond or millisecond accuracy, but it's generally not recommended +to rely on this high precision. + This interface suggests that cache implementations SHOULD use a monotonic time source if available. Given that a monotonic time source is only available as of PHP 7.3 by default, cache implementations MAY fall back diff --git a/src/CacheInterface.php b/src/CacheInterface.php index 76c3a6c..b51bf1b 100644 --- a/src/CacheInterface.php +++ b/src/CacheInterface.php @@ -50,6 +50,14 @@ public function get($key, $default = null); * This example eventually sets the value of the key `foo` to `bar`. If it * already exists, it is overridden. * + * This interface does not enforce any particular TTL resolution, so special + * care may have to be taken if you rely on very high precision with + * millisecond accuracy or below. Cache implementations SHOULD work on a + * best effort basis and SHOULD provide at least second accuracy unless + * otherwise noted. Many existing cache implementations are known to provide + * microsecond or millisecond accuracy, but it's generally not recommended + * to rely on this high precision. + * * This interface suggests that cache implementations SHOULD use a monotonic * time source if available. Given that a monotonic time source is only * available as of PHP 7.3 by default, cache implementations MAY fall back