Skip to content

Commit

Permalink
Updated to match repository 2.1.* versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Mar 18, 2016
1 parent 4340211 commit 4a1c11e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
}
],
"require": {
"nilportugues/repository": "^2.0",
"tedivm/stash": "v0.14.1"
"nilportugues/repository": "^2.1",
"tedivm/stash": "v0.14.*"
},
"require-dev": {
"phpunit/phpunit": "4.8.*",
Expand Down
39 changes: 39 additions & 0 deletions src/RepositoryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class RepositoryCache implements ReadRepository, WriteRepository, PageRepository
* @var string
*/
protected $cacheNamespaceFindBy;
/**
* @var string
*/
protected $cacheNamespaceFindByDistinct;
/**
* @var string
*/
Expand Down Expand Up @@ -82,6 +86,7 @@ protected function buildCacheKeys($classFQN)
$baseKey = str_replace('\\', '.', strtolower($classFQN));
$this->cacheNamespace = sprintf('/%s/', $baseKey);
$this->cacheNamespaceFindBy = sprintf('/%s/findby/', $baseKey);
$this->cacheNamespaceFindByDistinct = sprintf('/%s/finddistinct/', $baseKey);
$this->cacheNamespacePage = sprintf('/%s/paginated/', $baseKey);
$this->cacheNamespaceCount = sprintf('/%s/count/', $baseKey);
}
Expand Down Expand Up @@ -146,6 +151,7 @@ public function remove(Identity $id)
$this->cache->getItem($this->cacheNamespace.$id->id())->clear();
$this->cache->getItem($this->cacheNamespacePage)->clear();
$this->cache->getItem($this->cacheNamespaceFindBy)->clear();
$this->cache->getItem($this->cacheNamespaceFindByDistinct)->clear();
$this->cache->getItem($this->cacheNamespaceCount)->clear();

return $result;
Expand Down Expand Up @@ -216,4 +222,37 @@ public function removeAll(Filter $filter = null)

return $result;
}

/**
* {@inheritdoc}
*/
public function findByDistinct(
Fields $distinctFields,
Filter $filter = null,
Sort $sort = null,
Fields $fields = null
) {
$cachedItem = $this->cache->getItem(
$this->cacheNamespaceFindByDistinct.md5(
serialize($filter).serialize($sort).serialize($fields).serialize($distinctFields)
)
);

if (!$cachedItem->isMiss() && null !== ($result = $cachedItem->get())) {
return $result;
}

$result = $this->repository->findByDistinct($distinctFields, $filter, $sort, $fields);
$cachedItem->set($result, $this->cacheTime);

return $result;
}

/**
* {@inheritdoc}
*/
public function transactional(callable $transaction)
{
$this->repository->transactional($transaction);
}
}

0 comments on commit 4a1c11e

Please sign in to comment.