Skip to content

Add admin notification for Varnish purge object count#118

Open
peterjaap with Copilot wants to merge 6 commits into
masterfrom
copilot/add-admin-notification-purged-objects
Open

Add admin notification for Varnish purge object count#118
peterjaap with Copilot wants to merge 6 commits into
masterfrom
copilot/add-admin-notification-purged-objects

Conversation

Copilot AI commented Dec 15, 2025

Copy link
Copy Markdown
Contributor

Implements admin notification displaying the number of objects purged from Varnish cache. Previously, purge operations provided no visibility into how many objects were invalidated.

Changes

New notification class (Model/PurgeStatistics/Notification.php)

  • Implements MessageInterface with NOTICE severity
  • Displays: "Last cache purge: X object(s) were purged from Varnish. (Purged at: timestamp)"
  • Caches flag data to avoid duplicate DB queries

Enhanced purge handling (Model/PurgeCache.php)

  • Captures and parses Varnish HTTP responses containing {"invalidated": <count>}
  • Sums counts across all servers (previously discarded)
  • Stores statistics via FlagManager with timestamp
  • Handles both \r\n and \n line endings

Configuration (etc/adminhtml/di.xml)

  • Registers notification as standalone message, separate from critical Varnish warnings

Example

When Varnish purges 2 objects using xkey:

// Varnish VCL returns via vcl_synth:
set req.http.n-gone = xkey.purge("cat_p_694");
return (synth(200, req.http.n-gone));  // Response: {"invalidated": 2}

// PurgeCache now captures this:
$purgedCount = $this->parseVarnishResponse($response);  // 2
$this->storePurgeStatistics($totalObjectsPurged);       // Stores for notification

The notification persists in admin until the next purge operation updates it.

Original prompt

This section details on the original issue you should resolve

<issue_title>vcl_recv Add admin notification in Magento for number of purged objects</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)

@hpowernl For tomorrow only the admin part.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits December 15, 2025 09:53
- Created PurgeStatistics\Notification class to display purge information
- Modified PurgeCache to capture and parse Varnish responses
- Added parseVarnishResponse method to extract invalidated count from JSON
- Added storePurgeStatistics method to save purge data via FlagManager
- Registered new notification in adminhtml/di.xml

Co-authored-by: peterjaap <431360+peterjaap@users.noreply.github.com>
- Changed PurgeStatistics\Notification to implement MessageInterface directly
- Registered as separate notification in MessageList (not grouped with critical warnings)
- Added proper getIdentity() implementation
- Set severity to NOTICE for informational display

Co-authored-by: peterjaap <431360+peterjaap@users.noreply.github.com>
- Use json_decode() instead of regex for parsing Varnish responses
- Sum purged objects across servers instead of using max()
- Import PurgeStatsNotification class instead of using FQN
- Add caching to Notification::getStats() to avoid duplicate DB calls

Co-authored-by: peterjaap <431360+peterjaap@users.noreply.github.com>
@peterjaap peterjaap marked this pull request as ready for review December 15, 2025 09:58
Copilot AI and others added 2 commits December 15, 2025 09:59
- Update return type documentation to clarify int|false return type
- Improve getStats() clarity by using empty() instead of ternary operator

Co-authored-by: peterjaap <431360+peterjaap@users.noreply.github.com>
- Remove unnecessary blank line in Notification class
- Simplify isDisplayed() by removing redundant is_array check
- Handle both \r\n and \n line endings in HTTP response parsing
- Add is_array check before isset() for safer JSON parsing

Co-authored-by: peterjaap <431360+peterjaap@users.noreply.github.com>
Copilot AI changed the title [WIP] Add admin notification for purged objects in Magento Add admin notification for Varnish purge object count Dec 15, 2025
Copilot AI requested a review from peterjaap December 15, 2025 10:04
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

Successfully merging this pull request may close these issues.

vcl_recv Add admin notification in Magento for number of purged objects

2 participants