Skip to content

Commit

Permalink
fix: order manager caching (#821)
Browse files Browse the repository at this point in the history
* Fix order cache

The existing cache key does not take into account all parameters, leading to caching errors when e.g. loading page two (you will get a hit on the cache for the first page that was viewed and therefore cached).

This change automatically uses the entire args array to create the key, ensuring uniqueness.

* Update Manager.php

* Update Manager.php
  • Loading branch information
kvasbo authored May 11, 2020
1 parent a395300 commit b3bf1fd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions includes/Order/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ public function all( $args = [] ) {

$args = wp_parse_args( $args, $default );

$offset = ( $args['paged'] - 1 ) * $args['limit'];
$offset = ( $args['paged'] - 1 ) * $args['limit'];
$cache_group = 'dokan_seller_data_'.$args['seller_id'];
$cache_key = 'dokan-seller-orders-' . $args['status'] . '-' . $args['seller_id'];

// Use all arguments to create a hash used as cache key
$cache_key = 'dokan_seller_orders-' . md5(json_encode($args));

$orders = wp_cache_get( $cache_key, $cache_group );

$join = $args['customer_id'] ? "LEFT JOIN $wpdb->postmeta pm ON p.ID = pm.post_id" : '';
Expand Down

0 comments on commit b3bf1fd

Please sign in to comment.