<commit_before>"""                                                                              
 File Name : func_cache.py
                                                                              
 Creation Date : 19-09-2015
                                                                              
 Last Modified : Wed 07 Oct 2015 09:06:27 PM EDT
                                                                              
 Created By : <NAME>                                                    
                                                                              
 Purpose : Class wrapper for third-party lru cache. 
           Adds method used for reporting hits/misses.                                                                 
"""

from repoze.lru import lru_cache

class func_cache(lru_cache):

    def __init__(self, verbose=False):
        super(func_cache, self).__init__(500)
        self.verbose = verbose

    def ShowInfo(self):
        print "Cache results for:", self.FuncName
        print "hits:", self.cache.hits
        print "misses:", self.cache.misses
        print "lookups:", self.cache.lookups

    def __call__(self, f):
        lru_cached = super(func_cache, self).__call__(f)
        lru_cached.ShowInfo = self.ShowInfo
        self.FuncName = f.__name__
        return lru_cached

    def __del__(self):
        if (self.verbose):
            self.ShowInfo()

# Test functionality
if __name__ == '__main__':
    @func_cache()
    def rec(n):
        if not n:
            return n
        return rec(n-1)

    rec.ShowInfo()<commit_msg>Prints function name in ShowInfo<commit_after>"""                                                                              
 File Name : func_cache.py
                                                                              
 Creation Date : 19-09-2015
                                                                              
 Last Modified : Wed 07 Oct 2015 09:23:59 PM EDT
                                                                              
 Created By : <NAME>                                                    
                                                                              
 Purpose : Class wrapper for third-party lru cache. 
           Adds method used for reporting hits/misses.                                                                 
"""

from repoze.lru import lru_cache

class func_cache(lru_cache):

    def __init__(self, verbose=False):
        super(func_cache, self).__init__(500)
        self.verbose = verbose

    def ShowInfo(self):
        print "Cache results for:", self.FuncName
        print "   hits:", self.cache.hits
        print "   misses:", self.cache.misses
        print "   lookups:", self.cache.lookups, "\n"

    def __call__(self, f):
        lru_cached = super(func_cache, self).__call__(f)
        lru_cached.ShowInfo = self.ShowInfo
        self.FuncName = f.__name__
        return lru_cached

    def __del__(self):
        if (self.verbose):
            self.ShowInfo()

# Test functionality
if __name__ == '__main__':
    @func_cache()
    def rec(n):
        if not n:
            return n
        return rec(n-1)

    rec.ShowInfo()
{'fraction_non_alphanumeric': 0.07191568505889646, 'fraction_numerical': 0.014879107253564786, 'mean_word_length': 0.9416365824308063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2626483', 'n_tokens_mistral': 767, 'n_tokens_neox': 691, 'n_words': 192}