How to clear cache in python

What is Caching?
The process of caching enables storing of temporary data, the result of which is faster access, load times and speedier experience for the user. Deleting it makes the process to reload assets again.

Why to remove cache?
It is a good idea to clear your browser cache because it:
  • prevents you from using old forms
  • protects your personal information
  • helps our applications run better on your computer



Python code for clearing cache:
'''
Clear cache files 
'''
import os
if __name__=='__main__':
  outer = os.getcwd()
  cache = os.path.join(outer, 'cache')
  for f in os.listdir(cache):
    f = os.path.join(cache, f)
    os.remove(f)
  print("Removed {} files.".format(count))

if any doubts or queries please comment 🙂

Comments

Popular posts from this blog

Python and C++ program to implement multiplication of 2d array (Matrix multiplication)

What is AI (Artificial Intelligence )? and its characteristics

How to find and replace a node in Linked List