Forum Discussion
Leo
Nimbostratus
Jun 27, 2013Clearing machine cache
Hello all,
Today we are using a TMSH command to clear the machines cache by running:
delete ltm profile ramcache http-wan-optimized-compression-caching-cache
I want to be able to do this using an iRule, is there an equivalent command? or maybe a way to run TMSH command from an iRule?
4 Replies
- Yep. https://devcentral.f5.com/blogs/us/icall-all-new-event-based-automation-system.UcxCP9i6-6M
- Leo
Nimbostratus
So we're talking about 11.4?
Isn't there something similar to that tmsh command in iRule? - spark_86682Historic F5 AccountThere isn't directly, no. However, you can do something clever with CACHE_REQUEST, CACHE::age, and CACHE::expire. I can't code this up for you, but will describe how to do it. Basically, when you clear the cache at a certain time, any documents that were cached before that time get expired. You can do that in iRules, just not all at once. You would have some variable which contains a timestamp which is the last time you cleared the cache, and for each request you just check if the age of the document is longer than "time since cache was cleared" (which you do with CACHE::age, the clock command, and some math), and call CACHE::expire if it is. Then you need some way of updating that variable whenever you want to clear the cache. You probably want to store the variable in the session table, also.
- Leo
Nimbostratus
Thanks for the responses!
I eventually used the user_alert.conf file, here's what I did:
iRuleDelete cache on request, based on source IP iRule log triggers /config/user_alert.conf to clear the cache! when HTTP_REQUEST { Check URI if { [string tolower [HTTP::uri]] contains "delete-cache-now" } { set ip1 a.a.a.a/32 set ip2 b.b.b.b/32 set ip3 c.c.c.c/32 Check Source IP if { [IP::addr [IP::client_addr] equals $ip1] or [IP::addr [IP::client_addr] equals $ip2] or [IP::addr [IP::client_addr] equals $ip3] } { HTTP::respond 200 content "Cache CleanHello [IP::client_addr] Cache cleaned!" log local0. "EVENT-CACHE-DELETE-REQUEST-GOOD!!! - IP [IP::client_addr]" Stop processing iRules for this connection event disable return } } }
/config/user_alert.confalert Delete-Cache-Request "EVENT-CACHE-DELETE-REQUEST-GOOD!!!" { exec command="tmsh -c 'delete ltm profile ramcache http-wan-optimized-compression-caching-cache'" }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects