Skip to content

Instantly share code, notes, and snippets.

@mneuhaus
Created December 3, 2012 14:10
Show Gist options
  • Save mneuhaus/4195254 to your computer and use it in GitHub Desktop.
Save mneuhaus/4195254 to your computer and use it in GitHub Desktop.
Unique CachIdentifiers for Entities

Given:

$address = new \Address();
$address->zip = 12345;
$repository->add($address);

then the persistenceManager creates a cache entry:

2638z2387z283u2983t9820u3982z309z2930zu: Version1

Now you can get a unique identifier for that:

echo $cacheManager->getUniqueIdentifierByObject($address);
=> 2638z2387z283u2983t9820u3982z309z2930zu:Version1

When you change the address

$address->zip = 666666;
$persistenceManager->update($address);

then the persistenceManager updates the cache entry:

2638z2387z283u2983t9820u3982z309z2930zu: Version2

Which results in a new cache-identifiert for that address:

echo $cacheManager->getUniqueIdentifierByObject($address);
=> 2638z2387z283u2983t9820u3982z309z2930zu:Version2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment