Purging Akamai cache

To purge content from the cache on the Akamai edge servers, you can use the main LUNA control center, which will push the request out to the edge servers affected. As such, keep in mind the cache is not immediately purged.

EdgeControl management center is deprecated. Instead, navigate to publishing/content control utility in LUNA.

Enter the appropriate URL/ARL (Akamai Resource Locator)

You can also do CP codes. We only regularly invalidate the home page and category pages, not the entire catalog. This is because the home page and top level category pages have a TTL of 1 day. Catalog is only 45 minutes, so we simply wait for it to age off.

You can also make a RESTful web service call via http, using whatever client you use. You supply a JSON object with the list or ARL/URL’s or the cpcodes, and submit with authentication credentials to the URL.

A python implementation is below. This will submit the purge request, then query the status URI returned by the request to provide feedback on the progress.

import urllib2, base64, json, time, sys

if len(sys.argv) != 2:
  print "Please provide a comma separated list of cpcodes to purge"
  sys.exit(1)
else:
  headers = {"Content-type": "application/json", "Accept": "text/plain"}
  data = {"type":"cpcode","action":"invalidate","domain":"staging","objects":sys.argv[1].split(",")}
  req = urllib2.Request("https://api.ccu.akamai.com/ccu/v2/queues/default",json.dumps(data),headers)
  base64string = base64.encodestring('%s:%s' % ("your_name@your_email_domain.com","your_password")).replace('\n', '')
  req.add_header("Authorization", "Basic %s" % base64string) 
  resp = urllib2.urlopen(req).read()
  tmp = eval(resp)
  print tmp
  prog = tmp["progressUri"]

  print "progressUri = https://api.ccu.akamai.com" + prog + "\n"
  print "sleeping " + str(tmp["pingAfterSeconds"]) + " seconds until issuing the first check..."
  time.sleep(int(tmp["pingAfterSeconds"]) + 10)

  while True:
    req2 = urllib2.Request("https://api.ccu.akamai.com" + prog)
    req2.add_header("Authorization", "Basic %s" % base64string) 
    tmp = urllib2.urlopen(req2).read()
    status = eval(tmp.replace("null","None"))
    if status["purgeStatus"] == "Done":
      print "purge complete"
      sys.exit(0)
    else:
      print time.ctime() + '\tpurge still running...'
      time.sleep(30)

You will see output such as that below…

c:\>Python27\python.exe purge.py your CPcode
progressUri = https://api.ccu.akamai.com/ccu/v2/purges/ec98d52a-eb4f-11e3-a245-64002db3af9e

Mon Jun 09 10:27:59 2014        purge still running...
Mon Jun 09 10:28:30 2014        purge still running...
Mon Jun 09 10:29:01 2014        purge still running...
Mon Jun 09 10:29:31 2014        purge still running...
Mon Jun 09 10:30:02 2014        purge still running...
Mon Jun 09 10:30:32 2014        purge still running...
purge complete

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.