Make WordPress Core

Opened 3 years ago

Last modified 3 weeks ago

#24686 reopened enhancement

Introduce generic filter on transient return value

Reported by: johnbillion Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: Cache API Keywords: has-patch 2nd-opinion dev-feedback has-unit-tests
Focuses: Cc:


The get_transient() and get_site_transient() functions have a filter on their return value, but the filter name contains the transient key: transient_{$transient}.

This means it's not possible to hook into the return value for every transient in order to do something like logging transient hits and misses.

Attachments (3)

24686.patch (611 bytes) - added by johnbillion 3 years ago.
24686.2.patch (748 bytes) - added by adamsilverstein 3 weeks ago.
updated patch for new use case
24686.diff (2.7 KB) - added by welcher 3 weeks ago.
Adds unit tests

Download all attachments as: .zip

Change History (13)

3 years ago

#1 @johnbillion
3 years ago

  • Keywords has-patch added

#2 @johnbillion
3 years ago

Note that the patch on ticket #24685 is needed in conjunction with this to be of any real use.

#3 @wonderboymusic
3 years ago

  • Milestone changed from Awaiting Review to 3.7

#4 @nacin
3 years ago

Do we do anything similar for options, meta, or cache?

#5 @johnbillion
3 years ago

Nope, we don't do it for options, meta, or cache. I think it has a use case for transients though (and possibly the object cache, although that could impact performance). My use case is for logging hits and misses when fetching transients.

#6 @nacin
3 years ago

  • Keywords 2nd-opinion added
  • Milestone changed from 3.7 to Future Release

IRC discussion: http://irclogs.wordpress.org/chanlog.php?channel=wordpress-dev&day=2013-09-17&sort=asc#m689641

Maybe an 'expired_transient' action would be useful. But if you're using a cache backend, you'll get hit and miss statistics automatically.

#7 @johnbillion
3 years ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

3 weeks ago

updated patch for new use case

#8 @welcher
3 weeks ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened

I have a use case where a generic filter would be extremely useful.

I have written a plugin to bypass transients on a per page basis https://github.com/ryanwelcher/suspend-transients. In order to bypass transients, we need to know their names.

Getting the name requires retrieving them from the database or capturing them using the setted_transient action and then storing them somewhere ( in my case an option )

Once we have the names of the transients, we then have to add a filter for each one - which can be a very large number of filters to add - and will eventually cause performance issues.

Having a generic filter would address both these issues.

#9 @welcher
3 weeks ago

  • Keywords dev-feedback needs-unit-tests added

3 weeks ago

Adds unit tests

#10 @welcher
3 weeks ago

  • Keywords has-unit-tests added; needs-unit-tests removed
Note: See TracTickets for help on using tickets.