OrderCache.php
1 year ago
OrderCacheController.php
1 year ago
OrderCountCache.php
2 months ago
OrderCountCacheService.php
2 months ago
OrderCache.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Caches; |
| 4 | |
| 5 | use Automattic\WooCommerce\Caching\ObjectCache; |
| 6 | use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; |
| 7 | |
| 8 | /** |
| 9 | * A class to cache order objects. |
| 10 | */ |
| 11 | class OrderCache extends ObjectCache { |
| 12 | |
| 13 | /** |
| 14 | * Get the cache key and prefix to use for Orders. |
| 15 | * |
| 16 | * @return string |
| 17 | */ |
| 18 | public function get_object_type(): string { |
| 19 | if ( 'yes' === get_option( CustomOrdersTableController::HPOS_DATASTORE_CACHING_ENABLED_OPTION ) ) { |
| 20 | /** |
| 21 | * The use of datastore caching moves persistent data caching to the datastore. Order object caching then only |
| 22 | * acts as request level caching as the `order_objects` cache group is set as non-persistent. |
| 23 | */ |
| 24 | return 'order_objects'; |
| 25 | } else { |
| 26 | return 'orders'; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Get the id of an object to be cached. |
| 32 | * |
| 33 | * @param array|object $object The object to be cached. |
| 34 | * @return int|string|null The id of the object, or null if it can't be determined. |
| 35 | */ |
| 36 | protected function get_object_id( $object ) { |
| 37 | return $object->get_id(); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Validate an object before caching it. |
| 42 | * |
| 43 | * @param array|object $object The object to validate. |
| 44 | * @return string[]|null An array of error messages, or null if the object is valid. |
| 45 | */ |
| 46 | protected function validate( $object ): ?array { |
| 47 | if ( ! $object instanceof \WC_Abstract_Order ) { |
| 48 | return array( 'The supplied order is not an instance of WC_Abstract_Order, ' . gettype( $object ) ); |
| 49 | } |
| 50 | |
| 51 | return null; |
| 52 | } |
| 53 | } |
| 54 |