Title: libca1993's Replies | WordPress.org

---

# libca1993

  [  ](https://wordpress.org/support/users/libca1993/)

 *   [Profile](https://wordpress.org/support/users/libca1993/)
 *   [Topics Started](https://wordpress.org/support/users/libca1993/topics/)
 *   [Replies Created](https://wordpress.org/support/users/libca1993/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/libca1993/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/libca1993/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/libca1993/engagements/)
 *   [Favorites](https://wordpress.org/support/users/libca1993/favorites/)

 Search replies:

## Forum Replies Created

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

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP REST Cache] Clearing only affected or related caches](https://wordpress.org/support/topic/clearing-only-affected-or-related-caches/)
 *  Thread Starter [libca1993](https://wordpress.org/support/users/libca1993/)
 * (@libca1993)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/clearing-only-affected-or-related-caches/#post-16092837)
 * Hi [@rockfire](https://wordpress.org/support/users/rockfire/)
 * I also tried to clear cache using \WP_REST_Cache_Plugin\Includes\Caching\Caching::
   get_instance()->delete_related_caches( $post_id, $object_type );
 * Can you please provide me with and an example i’m falling to understand how use
   it. A sample code might help alot
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP REST Cache] Clearing only affected or related caches](https://wordpress.org/support/topic/clearing-only-affected-or-related-caches/)
 *  Thread Starter [libca1993](https://wordpress.org/support/users/libca1993/)
 * (@libca1993)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/clearing-only-affected-or-related-caches/#post-16092809)
 * Hi [@rockfire](https://wordpress.org/support/users/rockfire/)
 * So for the viriable and simple should classify them as product?
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP REST Cache] Clearing only affected or related caches](https://wordpress.org/support/topic/clearing-only-affected-or-related-caches/)
 *  Thread Starter [libca1993](https://wordpress.org/support/users/libca1993/)
 * (@libca1993)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/clearing-only-affected-or-related-caches/#post-16086429)
 * Hi
 * Thank you for your response,
 * I have tried to modify the object type to product but at this moment i didn’t
   modify for ‘product’ on object type is coming as simple or variable, But when
   i try to update a product the cache for that product is not being cleared.
 * is there anything i need todo?
 * here is the screen shot [Screen Shoot](https://media.packagerail.co.za/media/2022/10/10213423/Screenshot-2022-10-10-at-21.33.38.png)
 *     ```
       /**
        * Register endpoints so they will be cached.
        */
       function wprc_add_wc_endpoints( $allowed_endpoints ) {
           if ( ! isset( $allowed_endpoints[ 'wc/v3' ] ) || ! in_array( 'products', $allowed_endpoints[ 'wc/v3' ] ) ) {
               $allowed_endpoints[ 'wc/v3' ][] = 'products';
           }
           return $allowed_endpoints;
       }
       add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_wc_endpoints', 10, 1);
   
       function wprc_add_v2_wc_endpoints( $allowed_endpoints ) {
           if ( ! isset( $allowed_endpoints[ 'wc/v2' ] ) || ! in_array( 'products', $allowed_endpoints[ 'wc/v2' ] ) ) {
               $allowed_endpoints[ 'wc/v2' ][] = 'products';
           }
           return $allowed_endpoints;
       }
       add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_v2_wc_endpoints', 10, 1);
   
       function wprc_add_cacheable_request_headers( $cacheable_headers ) {
           $cacheable_headers['wc/v3/products'] = 'Authorization';
           return $cacheable_headers;
       }
       add_filter('wp_rest_cache/cacheable_request_headers', 'wprc_add_cacheable_request_headers', 10, 1);
   
       function wprc_v2_add_cacheable_request_headers( $cacheable_headers ) {
           $cacheable_headers['wc/v2/products'] = 'Authorization';
           return $cacheable_headers;
       }
       add_filter('wp_rest_cache/cacheable_request_headers', 'wprc_v2_add_cacheable_request_headers', 10, 1);
   
       function flutter_multi_vendor_wc_endpoints( $allowed_endpoints ) {
           if ( ! isset( $allowed_endpoints[ 'api/flutter_multi_vendor' ] ) || ! in_array( 'product', $allowed_endpoints[ 'api/flutter_multi_vendor' ] ) ) {
               $allowed_endpoints[ 'api/flutter_multi_vendor' ][] = 'product';
           }
           return $allowed_endpoints;
       }
       add_filter( 'wp_rest_cache/allowed_endpoints', 'flutter_multi_vendor_wc_endpoints', 10, 1);
       ```
   
 *     ```
       // Determine object type
       function wc_determine_object_type( $type, $cache_key, $data, $uri ) {
   
           if(strstr($uri,'category')){
               return 'category';
           }
           else if(strstr($uri, 'variations')){
               return 'variations';
           }else if ('/wp-json/wc/v2/products/attributes' === substr( $uri, 0, 34)){
               return 'attritubes';
           } else if  (strstr($uri, 'tags')){
               return 'tags';
           }else if ('/wp-json/api/flutter_multi_vendor/product-categories' === substr( $uri, 0, 52 ) ){
                return 'category';
            }
           return $type;
       }
       add_filter( 'wp_rest_cache/determine_object_type', 'wc_determine_object_type', 10, 4 );
       ```
   
    -  This reply was modified 3 years, 11 months ago by [libca1993](https://wordpress.org/support/users/libca1993/).

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