Make WordPress Core

Opened 11 years ago

Last modified 3 years ago

#24686 reviewing enhancement

Introduce generic filter on transient return value

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

Description

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 (6)

24686.patch (611 bytes) - added by johnbillion 11 years ago.
24686.2.patch (748 bytes) - added by adamsilverstein 7 years ago.
updated patch for new use case
24686.diff (2.7 KB) - added by welcher 7 years ago.
Adds unit tests
24686.2.diff (3.2 KB) - added by adamsilverstein 7 years ago.
24686.3.diff (1.0 KB) - added by adamsilverstein 7 years ago.
24686.4.diff (1.0 KB) - added by adamsilverstein 7 years ago.

Download all attachments as: .zip

Change History (22)

@johnbillion
11 years ago

#1 @johnbillion
11 years ago

  • Keywords has-patch added

#2 @johnbillion
11 years ago

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

#3 @wonderboymusic
11 years ago

  • Milestone changed from Awaiting Review to 3.7

#4 @nacin
11 years ago

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

#5 @johnbillion
11 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
10 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
10 years ago

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

@adamsilverstein
7 years ago

updated patch for new use case

#8 @welcher
7 years 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
7 years ago

  • Keywords dev-feedback needs-unit-tests added

@welcher
7 years ago

Adds unit tests

#10 @welcher
7 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

#11 @spbriggs
7 years ago

Could this also be added to get_site_transient?

#12 @netweb
7 years ago

  • Milestone set to Awaiting Review

Moving reopened tickets without a milestone back to Awaiting Review for review

#13 @adamsilverstein
7 years ago

24686.2.diff adds a matching filter for get_site_transient

24686.3.diff is an alternate version which fires actions before the transients are returned.

Offering do_action as an alternative based on the IRC discussion: http://irclogs.wordpress.org/chanlog.php?channel=wordpress-dev&day=2013-09-17&sort=asc#m689641

#14 @adamsilverstein
7 years ago

24686.4.diff rename hooks, change "getted" to "got".

#15 @adamsilverstein
7 years ago

@nacin, @johnbillion what do you think of the approach in 24686.4.diff triggering an action?

#16 @johnbillion
7 years ago

  • Owner set to johnbillion
  • Status changed from reopened to reviewing
Note: See TracTickets for help on using tickets.