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

Fetching same object instance #44

Closed
heruan opened this issue Sep 29, 2013 · 1 comment
Closed

Fetching same object instance #44

heruan opened this issue Sep 29, 2013 · 1 comment

Comments

@heruan
Copy link

heruan commented Sep 29, 2013

Two instances of the same object (i.e. $obj1 === $obj2) if stored and then fetched from cache should be the same instance again.

class A {}
$obj1 = new A();
$obj2 = $obj1;
var_dump($obj1 === $obj2); // true
apcu_store('obj1', $obj1);
apcu_store('obj2', $obj2);
var_dump(apcu_fetch('obj1') === apcu_fetch('obj2')); // false, but should be true

Semi-real use case:

class User {}
class Post {
    public $createdBy;
    public $editedBy;
}
$user = new User();
$post = new Post();
$post->createdBy = $user;
$post->editedBy = $user;
// persist $post to DB
// ...
// hydrate $post from DB and cache it
apcu_store('post', $post);
// ...
// fetch $post from cache
$post = apcu_fetch('post');
// now $post->createdBy and $post->editedBy are two different instances of class User, but they should be the same instance as the original
@krakjoe
Copy link
Owner

krakjoe commented Sep 30, 2013

You do not store the same physical object in the cache, that doesn't make any sense ...

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

2 participants