Changeset 2787887
- Timestamp:
- 09/20/2022 11:20:21 PM (4 years ago)
- Location:
- precious-metals-automated-product-pricing-pro/trunk
- Files:
-
- 2 edited
-
WooCommerce_Plugin_Nfusion.php (modified) (4 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
precious-metals-automated-product-pricing-pro/trunk/WooCommerce_Plugin_Nfusion.php
r2759355 r2787887 7 7 * Author URI: https://nfusionsolutions.com 8 8 * WC requires at least: 3.0.0 9 * WC tested up to: 6. 1.19 * WC tested up to: 6.9.2 10 10 * License: GPLv2 or later 11 11 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 12 12 13 * Version: 2.9.1 313 * Version: 2.9.14 14 14 */ 15 define("NFS_CATALOG_PLUGIN_VERSION", "2.9.13"); 15 define("NFS_CATALOG_PLUGIN_VERSION", "2.9.14"); 16 define("NFS_CATALOG_REMOTE_TIMEOUT_SECONDS", 2); 16 17 17 18 function nfs_catalog_plugin_tryGetProduct($skus){ … … 32 33 $currency = get_woocommerce_currency(); 33 34 $ttlSeconds = 60;//cache timeout in seconds 35 $ttlSecondarySeconds = 3600;//very long timeout for secondary cache 34 36 $productsMapKey = 'nfs_catalog_products_all_' . $currency; 37 $productsMapSecondaryKey = 'nfs_catalog_products_all_secondary_' . $currency; 35 38 //first check cache 36 39 $productsMap = get_transient($productsMapKey); … … 49 52 50 53 if ($fetchRemote === true) { 51 $productsMap = nfs_catalog_plugin_fetch_products_from_remote($currency); 52 if($productsMap !== false) { 53 //only cache if we got a valid response 54 set_transient($productsMapKey, $productsMap, $ttlSeconds); 55 } 56 else { 57 return false;//failed to find in cache and failed remote fetch 54 //we want too prevent many sessions from trying to make the remote call at the same time 55 //this can happen around cache expiry boundaries. The problem can become more pronounced if the remote 56 //server is slow to reponse, since the remote calls are blocking. An asynchronous approach with a true semaphore 57 //might be preferred here, but options are limited in WordPress/PHP stack without plugins (whose existence we cannot guarantee) 58 59 //here we will use a second transient as a sort of pseudo-semaphore. It will not truly prevent duplicate requests, but it may reduce them preventing stampede conditions. 60 $semaphoreKey = 'nfs_catalog_request_semaphore_' . $currency; 61 $semaphoreInUse = get_transient($semaphoreKey); 62 if ($semaphoreInUse === false || !isset($semaphoreInUse)) { 63 set_transient($semaphoreKey, true, NFS_CATALOG_REMOTE_TIMEOUT_SECONDS);//set transient ttl same as remote request timeout 64 $remoteResult = nfs_catalog_plugin_fetch_products_from_remote($currency); 65 if($remoteResult !== false) {//only cache if we got a valid response 66 //store the previous data in the secondary cache 67 set_transient($productsMapSecondaryKey, $productsMap, $ttlSecondarySeconds); 68 69 //store new data in first level cache 70 $productsMap = $remoteResult; 71 set_transient($productsMapKey, $productsMap, $ttlSeconds); 72 } 73 } 74 75 if ($productsMap === false || !isset($productsMap)) { 76 //if we don't have product data at this point, grab from secondary 77 $productsMap = get_transient($productsMapSecondaryKey); 58 78 } 59 79 } … … 72 92 73 93 $args = array( 94 'timeout' => NFS_CATALOG_REMOTE_TIMEOUT_SECONDS,//timeout in seconds 74 95 'headers' => array( 75 96 'User-Agent' => 'wpwc-'.NFS_CATALOG_PLUGIN_VERSION, -
precious-metals-automated-product-pricing-pro/trunk/readme.txt
r2759798 r2787887 5 5 License: GPLv2 or later 6 6 License URI: https://www.gnu.org/licenses/gpl-2.0.html 7 Tested up to: 5.97 Tested up to: 6.0.2 8 8 Requires at least: 3.5.0 9 Stable tag: 2.9.1 39 Stable tag: 2.9.14 10 10 11 11 Automated realtime metals spot and futures data dynamically updates product prices in your store for Gold, Silver, Platinum, and Palladium … … 145 145 * add compatibility for variable products 146 146 147 = 2.9.14 = 148 * cache performance enhancement 149 147 150 == Upgrade Notice == 148 151 Latest Stable Version
Note: See TracChangeset
for help on using the changeset viewer.