Returning an object from get() is fine, Drupal's been doing this for at
least 6 years or so (although it returns FALSE on misses rather than the
object to differentiate and the object is just stdClass()).

However putting set() and delete() methods on the cache item itself is
quite limiting.

Drupal has support for deleting multiple cache items at once by ID (and an
issue to add multiple set which I don't think is in yet), and that's not
covered by having methods on the individual cache object. You could of
course add that support somewhere else, but then you have two completely
places to do very similar things depending on whether it's single or
multiple operations. There's also no need to have an item class in order to
delete by ID - the whole point of deletion is getting rid of the item.

Nathaniel


On Mon, Oct 21, 2013 at 3:42 AM, Ray Ward <notifications@github.com> wrote:

> In proposed/cache.md:
>
> > +     *
> > +     * @param mixed $value
> > +     *   The serializable value to be stored.
> > +     * @param int|DateTime $ttl
> > +     *   - If an integer is passed, it is interpreted as the number of seconds
> > +     *     after which the item MUST be considered expired.
> > +     *   - If a DateTime object is passed, it is interpreted as the point in
> > +     *     time after which the the item MUST be considered expired.
> > +     *   - If no value is passed, a default value MAY be used. If none is set,
> > +     *     the value should be stored permanently or for as long as the
> > +     *     implementation allows.
> > +     * @return bool
> > +     *   Returns true if the item was successfully saved, or false if there was
> > +     *   an error.
> > +     */
> > +    function set($value = null, $ttl = null);
>
> The interfaces in this proposal are by no means perfect imo, but complex
> invalidation strategies shouldn't be cluttering up simple, low level
> interfaces though. They should be functionality that a library would be
> providing, building on top of the interfaces.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/php-fig/fig-standards/pull/149/files#r7084695>
> .
>