Caching in python

 



Hey guys once again welcome to the Decoders blog, I hope you all are doing well and today I'm present with online library(using PYTHON). The given code will help you to built it, so just follow the codes and make your own library, and enjoy it with your friends

WHAT  IS CACHING?

Caching is basically a method which helps us to reduce the runtime of any programme by  storing the value of the programme in its memory so that  that specific programme is needed to be executed later on then it does not take any time....... 

import time
from functools import lru_cache

@lru_cache(maxsize=3)
def some_work(n):
#Some task taking n seconds
time.sleep(n)
return n

if __name__ == '__main__':
print("fetching your data.......")
some_work(10)
print("here is your data......fetching again")
some_work(10)
print("here is data")

Comments

Popular Posts