Skip to content

Commit

Permalink
Update tag for preview cache (ezsystems#153)
Browse files Browse the repository at this point in the history
* Update tag for purging preview cache

The admin preview function does not display the draft content that is
currently being edited, this is because the preview cache is not purged,
and the preview function always fetches content from the view cache,
refer to ezsystems/ezpublish-kernel#2396 for details.

To fix this issue, `PersistenceCachePurger.php::contentVersion()` has
been changed to invalidate cache with the new tags.

| Question           | Answer
| ------------------ | ------------------
| **JIRA issue**     | n/a
| **Bug**            | yes
| **New feature**    | no
| **Target version** | `v2.0.0`
| **BC breaks**      | no
| **Tests pass**     | yes
| **Doc needed**     | no

**TODO**:
- [ ] Implement feature / fix a bug.
- [ ] Implement tests.
- [ ] Fix new code according to Coding Standards (`$ composer fix-cs`).
- [x] Ask for Code Review.

* Update PersistenceCachePurger.php

* Update PersistenceCachePurgerTest.php
  • Loading branch information
zerustech authored and andrerom committed Jul 31, 2018
1 parent aabfa43 commit 0bc476a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bundle/Cache/PersistenceCachePurger.php
Expand Up @@ -167,8 +167,9 @@ public function contentVersion($contentId, $versionNo)
return;
}

// todo Once we can require 2.2.2+, simplify to just invalidate "content-{$contentId}-version-{$versionNo}"
$this->cache->deleteItem("ez-content-version-info-${contentId}-${versionNo}");
$this->cache->invalidateTags(["content-${contentId}-version-list"]);
$this->cache->invalidateTags(["content-${contentId}-version-list", "content-{$contentId}-version-{$versionNo}"]);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions bundle/Tests/Cache/PersistenceCachePurgerTest.php
Expand Up @@ -389,4 +389,30 @@ public function testClearUserFail()
{
$this->cachePurger->user(new \stdClass());
}

/**
* @covers \eZ\Bundle\EzPublishLegacyBundle\Cache\PersistenceCachePurger::contentVersion
* @dataProvider getDataForTestClearVersionForOneContent
*/
public function testClearVersionOfOneContent($contentId, $versionNo)
{
$this->cacheService
->expects($this->once())
->method('deleteItem')
->with("ez-content-version-info-${contentId}-${versionNo}");

$this->cacheService
->expects($this->once())
->method('invalidateTags')
->with(["content-${contentId}-version-list", "content-${contentId}-version-${versionNo}"]);

$this->cachePurger->contentVersion($contentId, $versionNo);
}

public function getDataForTestClearVersionForOneContent()
{
return [
[18, 37],
];
}
}

0 comments on commit 0bc476a

Please sign in to comment.