clean_attachment_cache

Will clean the attachment in the cache.

Description

clean_attachment_cache( (int) $id, (bool) $clean_terms = false ); 

Cleaning means delete from the cache. Optionally will clean the term object cache associated with the attachment ID.

This function will not run if $_wp_suspend_cache_invalidation is not empty.

Parameters (2)

0. $id (int)
The attachment ID in the cache to clean.
1. $clean_terms — Optional. (bool) => false
Whether to clean terms cache. Default false.

Usage

  1. if ( !function_exists( 'clean_attachment_cache' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // The attachment ID in the cache to clean. 
  5. $id = -1; 
  6.  
  7. // Optional. Whether to clean terms cache. Default false. 
  8. $clean_terms = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = clean_attachment_cache($id, $clean_terms); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function clean_attachment_cache( $id, $clean_terms = false ) { 
  2. global $_wp_suspend_cache_invalidation; 
  3.  
  4. if ( !empty($_wp_suspend_cache_invalidation) ) 
  5. return; 
  6.  
  7. $id = (int) $id; 
  8.  
  9. wp_cache_delete($id, 'posts'); 
  10. wp_cache_delete($id, 'post_meta'); 
  11.  
  12. if ( $clean_terms ) 
  13. clean_object_term_cache($id, 'attachment'); 
  14.  
  15. /** 
  16. * Fires after the given attachment's cache is cleaned. 
  17. * @since 3.0.0 
  18. * @param int $id Attachment ID. 
  19. */