PHP Classes

File: manuscript/Working with Pimf_Util_IdentityMap.md

Recommend this page to a friend!
  Classes of Gjero Krsteski   PIMF   manuscript/Working with Pimf_Util_IdentityMap.md   Download  
File: manuscript/Working with Pimf_Util_IdentityMap.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: PIMF
Framework for Web application development
Author: By
Last change: Update of manuscript/Working with Pimf_Util_IdentityMap.md
Date: 5 months ago
Size: 778 bytes
 

Contents

Class file image Download

Identity-Map

The identity map pattern is a database access design pattern used to improve performance by providing a context-specific, in-memory cache to prevent duplicate retrieval of the same object data from the database.

$blogEntry = new AnyModelObject();
$id        = 'some-unique-id-here';

$identityMap = new Pimf\Util\IdentityMap();

if (true === $identityMap->hasId($id)) {
  return $identityMap->getObject($id);
}

Setting objects/instances inti the identity map.

$identityMap->set($id, $blogEntry);

if (true === $identityMap->hasObject($blogEntry)) {
  throw new RuntimeException('Object has an ID, cannot insert.');
}

Please find more here: github.com/gjerokrsteski/php-identity-map