Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stop memoizing the filter input and output to prevent memory leakage. F…
  • Loading branch information
jezdez committed Nov 2, 2011
1 parent 44f1b04 commit 74cc5bd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 33 deletions.
8 changes: 3 additions & 5 deletions compressor/base.py
Expand Up @@ -17,7 +17,7 @@
from compressor.storage import default_storage, compressor_file_storage
from compressor.signals import post_compress
from compressor.utils import get_class, staticfiles
from compressor.utils.decorators import cached_property, memoize
from compressor.utils.decorators import cached_property

# Some constants for nicer handling.
SOURCE_HUNK, SOURCE_FILE = 'inline', 'file'
Expand Down Expand Up @@ -119,7 +119,6 @@ def cachekey(self):
return get_hexdigest(''.join(
[self.content] + self.mtimes).encode(self.charset), 12)

@memoize
def hunks(self, mode='file', forced=False):
"""
The heart of content parsing, iterates of the
Expand Down Expand Up @@ -157,15 +156,13 @@ def hunks(self, mode='file', forced=False):
else:
yield mode, self.parser.elem_str(elem)

@memoize
def filtered_output(self, content):
"""
Passes the concatenated content to the 'output' methods
of the compressor filters.
"""
return self.filter(content, method=METHOD_OUTPUT)

@memoize
def filtered_input(self, mode='file', forced=False):
"""
Passes each hunk (file or code) to the 'input' methods
Expand Down Expand Up @@ -267,6 +264,7 @@ def render_output(self, mode, context=None):
final_context.update(self.context)
final_context.update(context)
final_context.update(self.extra_context)
post_compress.send(sender='django-compressor', type=self.type, mode=mode, context=final_context)
post_compress.send(sender='django-compressor', type=self.type,
mode=mode, context=final_context)
return render_to_string("compressor/%s_%s.html" %
(self.type, mode), final_context)
28 changes: 0 additions & 28 deletions compressor/utils/decorators.py
@@ -1,31 +1,3 @@
import functools

class memoize(object):

def __init__ (self, func):
self.func = func

def __call__ (self, *args, **kwargs):
if (args, str(kwargs)) in self.__dict__:
value = self.__dict__[args, str(kwargs)]
else:
value = self.func(*args, **kwargs)
self.__dict__[args, str(kwargs)] = value
return value

def __repr__(self):
"""
Return the function's docstring.
"""
return self.func.__doc__ or ''

def __get__(self, obj, objtype):
"""
Support instance methods.
"""
return functools.partial(self.__call__, obj)


class cached_property(object):
"""Property descriptor that caches the return value
of the get function.
Expand Down

0 comments on commit 74cc5bd

Please sign in to comment.