/var/www/html_us/wp-content/plugins/woocommerce/src/Caches/OrderCacheController.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php

namespace Automattic\WooCommerce\Caches;

use 
Automattic\WooCommerce\Internal\Features\FeaturesController;
use 
Automattic\WooCommerce\Utilities\OrderUtil;

/**
 * A class to control the usage of the orders cache.
 */
class OrderCacheController {

    
/**
     * The orders cache to use.
     *
     * @var OrderCache
     */
    
private $order_cache;

    
/**
     * The orders cache to use.
     *
     * @var FeaturesController
     */
    
private $features_controller;

    
/**
     * The backup value of the cache usage enable status, stored while the cache is temporarily disabled.
     *
     * @var null|bool
     */
    
private $orders_cache_usage_backup null;

    
/**
     * Class initialization, invoked by the DI container.
     *
     * @internal
     * @param OrderCache $order_cache The order cache engine to use.
     */
    
final public function initOrderCache $order_cache ) {
        
$this->order_cache $order_cache;
    }

    
/**
     * Whether order cache usage is enabled. Currently, linked to custom orders' table usage.
     *
     * @return bool True if the order cache is enabled.
     */
    
public function orders_cache_usage_is_enabled(): bool {
        return 
OrderUtil::custom_orders_table_usage_is_enabled();
    }

    
/**
     * Temporarily disable the order cache if it's enabled.
     *
     * This is a purely in-memory operation: a variable is created with the value
     * of the current enable status for the feature, and this variable
     * is checked by orders_cache_usage_is_enabled. In the next request the
     * feature will be again enabled or not depending on how the feature is set.
     */
    
public function temporarily_disable_orders_cache_usage(): void {
        if ( 
$this->orders_cache_usage_is_temporarly_disabled() ) {
            return;
        }

        
$this->orders_cache_usage_backup $this->orders_cache_usage_is_enabled();
    }

    
/**
     * Check if the order cache has been temporarily disabled.
     *
     * @return bool True if the order cache is currently temporarily disabled.
     */
    
public function orders_cache_usage_is_temporarly_disabled(): bool {
        return 
null !== $this->orders_cache_usage_backup;
    }

    
/**
     * Restore the order cache usage that had been temporarily disabled.
     */
    
public function maybe_restore_orders_cache_usage(): void {
        
$this->orders_cache_usage_backup null;
    }
}