We are building a product catalog that displays availability (via a snippet that queries the database) of each product. Items sell slow, so I am wanting to cache the snippet output to decrease the number of database queries and speed things up at the viewer's end.
Once this is done, I am wondering if there is a method to then clear a specific page cache remotely. Perhaps a PHP snippet we can add to our shopping cart check out function to tell MODX to clear the cache for that product's page. Then the next visitor would cause the availability to be updated and cached.
The shopping cart sits outside of MODX because I am too lazy to tear it apart into template, chunks and snippets (too darn much underlying php). But they are both in the same file structure.
-
☆ A M B ☆
- 3,141 Posts
In situations like that I tend to write the output to another cache partition, ie not with the resource cache but separate. In my custom snippet to view the products I would then get that using the cacheManager, or let it run normally and write the result to the cache for the next load.
Clearing it would then simply use the cachemanager for my partition too.
See this for some quick intros to caching:
https://forums.modx.com/thread/31410/revolution-clear-cache-of-custom-components
-
☆ A M B ☆
- 3,112 Posts
Through FTP, browse to
/core/cache/resource/web/resources/
The [id].cache.php is the page's cache
The /[id]/ folder contains element's caches on that particular page.
Delete manually which is your target.
Rico
Genius is one percent inspiration and ninety-nine percent perspiration.
Thomas A. Edison
MODx is great, but knowing how to use it well makes it perfect!
www.virtudraft.com
Security, security, security! |
Indonesian MODx Forum |
MODx Revo's cheatsheets |
MODx Evo's cheatsheets
Author of
Easy 2 Gallery 1.4.x,
PHPTidy,
spieFeed,
FileDownload R,
Upload To Users CMP,
Inherit Template TV,
LexRating,
ExerPlan,
Lingua,
virtuNewsletter,
Grid Class Key,
SmartTag,
prevNext
Maintainter/contributor of
Babel
Because it's hard to follow all topics on the forum, PING ME ON TWITTER
@_goldsky if you need my help.
Thanks for the suggestions. I definitely don't want to do this manually, it needs to be done automatically upon submission of the shopping cart. And the other drawback is that the call to clear the cache is coming from a webpage outside of MODX.
Looking at Mark's suggestion, I am not clear as to how I can call that function from outside MODX, as it seems to be more of an internal function.
But the info Goldsky gave on where the cache is located, got me thinking laterally that perhaps I can use PHP's unlink function to delete the specified file (core/cache/resource/web/resources/$id.cache.php)
-
☆ A M B ☆
- 3,141 Posts
array_map('unlink', glob("../core/cache/resource/web/resources/*.php")); //for modx cache
seems to work