Make WordPress Core

Opened 11 years ago

Last modified 10 days ago

#22369 reopened defect (bug)

get_transient() do not call delete_transient() when deleting one

Reported by: juliobox's profile juliobox Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: General Keywords: close
Focuses: Cc:

Description

Hello

i was wondering why get_transient() is not calling delete_transient when deleting a timeouted transient.

Piece of code from get_transient()

				$transient_option = '_transient_' . $transient;
				$transient_timeout = '_transient_timeout_' . $transient;
				if ( get_option( $transient_timeout ) < time() ) {
					delete_option( $transient_option  );
					delete_option( $transient_timeout );
					return false;
				}

but i need to trigger the "deleted_transient" hook.
Can we do that:

				$transient_option = '_transient_' . $transient;
				$transient_timeout = '_transient_timeout_' . $transient;
				if ( get_option( $transient_timeout ) < time() ) {
					delete_transient( $transient_option  );
					return false;
				}

Change History (4)

#1 @nacin
11 years ago

  • Keywords close added
  • Version changed from trunk to 2.8

The transient isn't being "deleted" — it has simply expired and we've used the opportunity here to clean it up. (We could just as easily do it on cron or on upgrade — things we've considered.) A separate "expired transient" hook could be beneficial, but it wouldn't always work. That's because in environments with an object caching backend such as APC or Memcache, transient caching is completely offloaded there. Data in an external backend could get pushed out of cache at any time.

I do think the return false should go through the existing transient_$transient filter, though. When using an external backend, the false from wp_cache_get() does go through the filter, so this should as well.

#2 @juliobox
11 years ago

ok i understand, thank you !

#3 @johnbillion
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

I've opened #24685 for the transient_$transient filter issue. Going to close this one as invalid becase, as nacin stated, the transient isn't being deleted at this point, it has expired.

Version 0, edited 11 years ago by johnbillion (next)

#4 @juliobox
10 days ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

Hey there, i'm back.
So if it has expired, why not trigger an action hook?

				$transient_option = '_transient_' . $transient;
				$transient_timeout = '_transient_timeout_' . $transient;
				if ( get_option( $transient_timeout ) < time() ) {
					delete_option( $transient_option  );
					delete_option( $transient_timeout );
					do_action( 'transient_expired', $transient, $timeout );
					return false;
				}

Thanks

Note: See TracTickets for help on using tickets.