public function set($value = null, $ttl = null)
    {
        $now = new DateTime();

        // whoever came up with the idea of allowing int AND datetime...
        // so lets convert this to an int (its a time to live, not a date to delete ffs)
        if ($ttl instanceof DateTime) {
            $ttl = $ttl->getTimestamp() - $now->getTimestamp();
        }

        $data = [
            "updated" => $now,
            "value" => $value,
            "key" => $this->key,
            "ttl" => $ttl
        ];

        return false !== file_put_contents($this->filename, serialize($data));
    }
public function set($value = null, $ttl = null)
    {
        $now = new DateTime();

        // whoever came up with the idea of allowing int AND datetime...
        // so lets convert this to an int (its a time to live, not a date to delete ffs)
        if ($ttl instanceof DateTime) {
            $ttl = $ttl->getTimestamp() - $now->getTimestamp();
        }

        $data = [
            "updated" => $now,
            "value" => $value,
            "key" => $this->key,
            "ttl" => $ttl
        ];

        return false !== file_put_contents($this->filename, serialize($data));
    }
public function set ( $ value = null , $ ttl = null ) { $ now = new DateTime ( ) ; // whoever came up with the idea of allowing int AND datetime... // so lets convert this to an int (its a time to live, not a date to delete ffs) if ( $ ttl instanceof DateTime ) { $ ttl = $ ttl -> getTimestamp ( ) - $ now -> getTimestamp ( ) ; } $ data = [ "updated" => $ now , "value" => $ value , "key" => $ this -> key , "ttl" => $ ttl ] ; return false !== file_put_contents ( $ this -> filename , serialize ( $ data ) ) ; }
Stores a value into the cache.

The $value argument may be any item that can be serialized by PHP,
although the method of serialization is left up to the Implementing
Library.

Implementing Libraries MAY provide a default TTL if one is not specified.
If no TTL is specified and no default TTL has been set, the TTL MUST
be set to the maximum possible duration of the underlying storage
mechanism, or permanent if possible.

@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.
Stores a value into the cache .