Skip to content

Commit

Permalink
Set a WP transient expiration one year in the future instead of makin…
Browse files Browse the repository at this point in the history
…g it indefinite.

* With the default options-table based transient cache, indefinitely stored transients are autoloaded.
* By setting an expiration date in the far-future, it is *effectively* indefinite, but we get the benefit of no autoloading of what might be a very large options row.

props to @YousefED for bringing the issue to my attention. fixes #10
  • Loading branch information
markjaquith committed Dec 20, 2012
1 parent f2b88b5 commit f388488
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tlc-transients.php
Expand Up @@ -94,9 +94,9 @@ public function fetch_and_cache() {

public function set( $data ) {
// We set the timeout as part of the transient data.
// The actual transient has no TTL. This allows for soft expiration.
// The actual transient has a far-future TTL. This allows for soft expiration.
$expiration = ( $this->expiration > 0 ) ? time() + $this->expiration : 0;
set_transient( 'tlc__' . $this->key, array( $expiration, $data ) );
set_transient( 'tlc__' . $this->key, array( $expiration, $data ), 31536000 ); // 60*60*24*365 ~= one year
return $this;
}

Expand Down

0 comments on commit f388488

Please sign in to comment.