• Resolved locomo

    (@locomo)


    Is there a hook to purge the transient cache of a specific table?

    I want to purge the cache whenever a certain custom post type gets edited.

    • This topic was modified 9 years, 6 months ago by locomo.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    That transient cache is purged whenever a table is saved, so that would probably be the best way to do it for a single table. For details, I suggest to take a look at the model-table.php file.

    To purge the caches of all tables, you could use the function TablePress::$model_table->invalidate_table_output_caches(); in that file.

    Regards,
    Tobias

    Thread Starter locomo

    (@locomo)

    Thanks for the fast reply!

    Would you consider adding a public version of this function:
    protected function _invalidate_table_output_cache( $table_id ) {

    that way we could invalidate the cache in a more targeted manner?

    i’m adding data to a table dynamically rather than via your backend interface .. so I don’t explicitly save the table when new data is available

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    yes, I should probably do that.

    How about adding this as a compatibility layer?

    /**
     * Delete all transients used for output caching of a table (e.g. when the table is updated or deleted).
     *
     * @since 1.8.0
     *
     * @param string $table_id Table ID.
     */
    public function invalidate_table_output_cache( $table_id ) {
    	$this->_invalidate_table_output_cache( $table_id );
    }

    to get a public version named invalidate_table_output_cache?

    I could probably also simply rename the function, change its scope, and fix the name wherever the function is called, as it was protected initially, or do you see any drawbacks there?

    Regards,
    Tobias

    Thread Starter locomo

    (@locomo)

    i personally like how you wrapped the protected function .. seems more flexible down the road? but either way it looks great

    thank you

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    great! Thanks for your feedback!

    I went for renaming and changing the scope, as I don’t see a use of having both the protected and the public version of the function. This will be part of the upcoming TablePress 1.8 release (probably after Christmas or early next year).

    For “early” compatibility in your code, you could just add the wrapper function to your local copy of that TablePress PHP file. As the function name is the same, everything will continue to work even after updating to TablePress 1.8 then.

    Regards,
    Tobias

    Thread Starter locomo

    (@locomo)

    awesome!!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!

    Best wishes,
    Tobias

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘manually purge the cache?’ is closed to new replies.