[PSR-6 Cache] Expiration time on updated item

279 views
Skip to first unread message

Tobias Nyholm

unread,
Jan 11, 2016, 1:21:33 PM1/11/16
to PHP Framework Interoperability Group

Consider this:

// T = 0
$item = $pool->getItem('key');
$item->set('value');
$item->expiresAfter(3600);
$pool->save($item);

// T = 600
$item = $pool->getItem('key');
$item->set('foobar');
$pool->save($item);

For how long is the item still in cache? The way I see it there are three options:

  • A) Until T=3600
  • B) Until T=4200
  • C) Forever since $item->expiresAfter() was never called.

I believe that option A is preferable. What do you think? What was intended?

Matt Kynaston

unread,
Jan 13, 2016, 12:15:01 PM1/13/16
to PHP Framework Interoperability Group
Definitely not B! I think that breaks the whole idea of TTL.

Both A and  B require the implementing library to store the expiry along with the cache item. Not many of the native caching backends (apcu, memcached, etc) support this. Of the ones in pecl, I think only wincache provides a way of getting this info.

I can't find anything in the spec that says the cache item has to know about it's previous expiration, and `getExpiration()` was removed as "useless" after this discussion:

I also think explicitly setting the TTL on save makes it one hell of a lot clearer what's happening in the code. With option A), what would you do if you wanted to use the implementing library's default on the second save?

And finally, how about:

// T = 0
$item = $pool->getItem('key');
$item->set('value'
);
$item->expiresAt(new \DateTime('+2seconds'));
$pool->save($item);
// T = 5
$item = $pool->getItem('key');
$item->set('foobar');
$pool->save($item);

Have you just attempted to save an already-expired item?

So I'm for C :)

Larry Garfield

unread,
Jan 13, 2016, 12:25:35 PM1/13/16
to php...@googlegroups.com
On 1/13/16 11:15 AM, Matt Kynaston wrote:
>
>
> On Monday, 11 January 2016 18:21:33 UTC, Tobias Nyholm wrote:
>
> Consider this:
>
> // T = 0
> $item = $pool->getItem('key');
> $item->set('value');
> $item->expiresAfter(3600);
> $pool->save($item);
>
> // T = 600
> $item = $pool->getItem('key');
> $item->set('foobar');
> $pool->save($item);
>
> For how long is the item still in cache? The way I see it there
> are three options:
>
> * A) Until T=3600
> * B) Until T=4200
> * C) Forever since |$item->expiresAfter()| was never called.
>
> I believe that option A is preferable. What do you think? What was
> intended?
>
>
> Definitely not B! I think that breaks the whole idea of TTL.
>
> Both A and B require the implementing library to store the expiry
> along with the cache item. Not many of the native caching backends
> (apcu, memcached, etc) support this. Of the ones in pecl, I think only
> wincache provides a way of getting this info.
>
> I can't find anything in the spec that says the cache item has to know
> about it's previous expiration, and `getExpiration()` was removed as
> "useless" after this discussion:
> https://groups.google.com/forum/#!searchin/php-fig/getExpiration/php-fig/vbG1DcchdjI/Y3b546PoCwAJ
>
> I also think explicitly setting the TTL on save makes it one hell of a
> lot clearer what's happening in the code. With option A), what would
> you do if you wanted to use the implementing library's default on the
> second save?
>
> And finally, how about:
>
> // T = 0
> $item= $pool->getItem('key');
> $item->set('value');
> $item->expiresAt(new \DateTime('+2seconds')); $pool->save($item);
> // T = 5
> $item= $pool->getItem('key');
> $item->set('foobar');
> $pool->save($item);
>
> Have you just attempted to save an already-expired item?
>
> So I'm for C :)

Yes, C is the intent here. Each save call should be a complete
"command" object, in essence.

--
--Larry Garfield

Matteo Beccati

unread,
Jan 13, 2016, 12:27:16 PM1/13/16
to php...@googlegroups.com
On 11/01/2016 19:21, Tobias Nyholm wrote:
> Consider this:
>
> // T = 0
> $item = $pool->getItem('key');
> $item->set('value');
> $item->expiresAfter(3600);
> $pool->save($item);
>
> // T = 600
> $item = $pool->getItem('key');
> $item->set('foobar');
> $pool->save($item);
>
> For how long is the item still in cache? The way I see it there are
> three options:
>
> * A) Until T=3600
> * B) Until T=4200
> * C) Forever since |$item->expiresAfter()| was never called.
>
> I believe that option A is preferable. What do you think? What was intended?

I think I've raised similar concerns a long time ago, which led to
removing the getExpiration() method.

I believe the correct answer in this case is C (the default ttl / forever).


Cheers
--
Matteo Beccati

Development & Consulting - http://www.beccati.com/

Jeremy Lindblom

unread,
Jan 13, 2016, 12:41:58 PM1/13/16
to php...@googlegroups.com
Is there anything we should do to clarify this or prevent this question from being asked again?

--
Jeremy Lindblom (@jeremeamia)
Software/Platform Engineer at Engrade (part of McGraw-Hill Education)
Co-author of the AWS SDK for PHP (@awsforphp)
PHP-FIG Representative for the Guzzle project

Looking for a senior-level software engineering position doing PHP? I have some available with McGraw-Hill Education in Seattle and Los Angeles (Santa Monica or Irvine). Contact me for me more information.



--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/569688E6.7090903%40beccati.com.
For more options, visit https://groups.google.com/d/optout.

Larry Garfield

unread,
Jan 13, 2016, 12:45:55 PM1/13/16
to php...@googlegroups.com
Sounds like an errata entry to me. PR welcome. Would that require a vote?

On 1/13/16 11:41 AM, Jeremy Lindblom wrote:
> Is there anything we should do to clarify this or prevent this
> question from being asked again?
>
> --
> *Jeremy Lindblom (@jeremeamia <https://twitter.com/jeremeamia>)*
> Software/Platform Engineer at Engrade <https://engrade.com/> (part of
> McGraw-Hill Education <http://www.mheducation.com/>)
> Co-founder of the Pacific Northwest PHP Conference
> <http://pnwphp.com/> (@PNWPHP <https://twitter.com/pnwphp>)
> Co-author of the AWS SDK for PHP
> <http://aws.amazon.com/sdkforphp/> (@awsforphp
> <https://twitter.com/awsforphp>)
> PHP-FIG <http://www.php-fig.org/> Representative for the Guzzle
> <http://guzzlephp.org/> project
> <mailto:php-fig%2Bunsu...@googlegroups.com>.
> To post to this group, send email to php...@googlegroups.com
> <mailto:php...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/php-fig/569688E6.7090903%40beccati.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "PHP Framework Interoperability Group" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to php-fig+u...@googlegroups.com
> <mailto:php-fig+u...@googlegroups.com>.
> To post to this group, send email to php...@googlegroups.com
> <mailto:php...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/php-fig/CALDVup%2BcCvsuPtKt82cRh4J%3D6epWoTaSu5ygMG8canyyTFT%2BCQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/php-fig/CALDVup%2BcCvsuPtKt82cRh4J%3D6epWoTaSu5ygMG8canyyTFT%2BCQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
--Larry Garfield

Tobias Nyholm

unread,
Jan 13, 2016, 2:44:52 PM1/13/16
to PHP Framework Interoperability Group
Thank you for the answers

I will add it to the integration tests: https://github.com/php-cache/integration-tests
They are getting more and more attention. So that might help you not to answer this question again. 
Reply all
Reply to author
Forward
0 new messages