Skip to content

Commit

Permalink
removed Cobject attribute
Browse files Browse the repository at this point in the history
Signed-off-by: Anto Idicherian Lonappan <[email protected]>
  • Loading branch information
antolonappan committed Apr 2, 2023
1 parent 488797e commit 71ca3c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pycachera/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .cacher import Cache as cache

__version__ = "2.1.0"
__version__ = "3.0.0"
__author__ = "Anto I Lonappan"
__author_email__ = "[email protected]"
__description__ = "A simple and powerful python cache decorator"
17 changes: 10 additions & 7 deletions pycachera/cacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Cache(object):
>>> return x**2
"""

def __init__(self,cachefolder=None,extrarg=None,cachekey=None,verbose=False,Cobject="class",recache=False):
def __init__(self,cachefolder=None,extrarg=None,cachekey=None,verbose=False,recache=False):

if cachefolder is None:
cachefolder = os.path.join(os.getcwd(),'.cache')
Expand All @@ -36,7 +36,7 @@ def __init__(self,cachefolder=None,extrarg=None,cachekey=None,verbose=False,Cobj
if verbose: print(f"PyCache: Setting '{cachefolder}' as Cache folder")

self.cachefolder = cachefolder
self.Cobject = Cobject
self.Cobject = None
self.extrarg = extrarg
self.recache = recache

Expand All @@ -48,11 +48,16 @@ def __init__(self,cachefolder=None,extrarg=None,cachekey=None,verbose=False,Cobj

def __call__(self, func):
def decorator(*args,**kargs):

if (len(args) == 0) or len(str(args[0].__class__).split(".")) == 1:
self.Cobject = 'function'
else:
self.Cobject = 'class'

if self.Cobject=="class":
fileprefix = f"""{self.cachefolder}/{str(args[0].__class__).split(".")[-1].split("'")[0]}_{func.__name__}"""
elif self.Cobject=="function":
fileprefix = f"{self.cachefolder}/{func.__name__}"

if not os.path.exists(fileprefix):
os.makedirs(fileprefix)

Expand All @@ -75,7 +80,7 @@ def decorator(*args,**kargs):
return cache
return decorator

def cachekey_gen(self, arg,karg={}):
def cachekey_gen(self,arg,karg={}):
"""
Generates a unique key for a function, depending on the args
Expand All @@ -84,13 +89,11 @@ def cachekey_gen(self, arg,karg={}):
few properties of the args. Currently it cannot handle a complex args,
but still it does a pretty good job
"""
Earg = []
if self.Cobject == "class":
Earg = []
if self.extrarg is not None:
for earg in self.extrarg:
Earg.append(getattr(arg[0], earg))
elif self.Cobject == "function":
Earg = []


a = ''
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name = 'pycachera',
packages = ['pycachera'],
package_data = {'pycachera' : files },
version = '2.1.0',
version = '3.0.0',
install_requires = ['numpy','pandas'],
description = 'A powerfull python caching tool',
author = 'Anto Idicherian Lonappan',
Expand Down

0 comments on commit 71ca3c0

Please sign in to comment.