Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache.php#save behavior depending on the adapter method #31

Closed
bitbucket-import opened this issue Aug 19, 2011 · 1 comment
Closed

Cache.php#save behavior depending on the adapter method #31

bitbucket-import opened this issue Aug 19, 2011 · 1 comment

Comments

@bitbucket-import
Copy link

Hi,

Adapter currently available (dummy, file, apc, memcached) of, file, apc on, save method, but the behavior of the data to be overwritten, memcached on, not over, they become new additions.

Maybe, but I think a small mistake, such as implementing a fundamentally different behavior using the same interface, so I think that is wrong, memcached think is right even if the override.

Memcache:: add instead the following Memcache:: set method that I think is right.
http://www.php.net/manual/en/memcache.set.php

=== system/libraries/Cache/drivers/Cache_file.php ===
{{{

!php

public function save($id, $data, $ttl = 60)
{       
    $contents = array(
            'time'      => time(),
            'ttl'       => $ttl,            
            'data'      => $data
        );

    if (write_file($this->_cache_path.$id, serialize($contents)))
    {
        @chmod($this->_cache_path.$id, 0777);
        return TRUE;            
    }

    return FALSE;
}

}}}

=== system/libraries/Cache/drivers/Cache_apc.php ===
{{{

!php

public function save($id, $data, $ttl = 60)
{
    return apc_store($id, array($data, time(), $ttl), $ttl);
}

}}}

=== system/libraries/Cache/drivers/Cache_memcached.php ===
{{{

!php

public function save($id, $data, $ttl = 60)
{
    return $this->_memcached->add($id, array($data, time(), $ttl), $ttl);
}

}}}

@johnbellone
Copy link
Contributor

I think that ::set may be the correct method. The function save is quite ambiguous - you want the value to be stored even if the key already exists - but the ::add method on the PHP documents only adds if the value doesn't already exist. I will test to see if the ::set method will add if the value doesn't exist, which is my guess, and thus a set is the correct behavior.

@gaker gaker closed this as completed in 284dd97 Aug 21, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants