Rename cache_state_backend to image_cache_backend

Related names (like the package and class names) have also been
updated.
This commit is contained in:
Matthew Tretter 2012-02-12 16:18:34 -05:00
parent 15b15afe2c
commit e9e364eedd
3 changed files with 29 additions and 29 deletions

View file

@ -2,9 +2,9 @@ from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module from django.utils.importlib import import_module
class PessimisticCacheStateBackend(object): class PessimisticImageCacheBackend(object):
""" """
A very safe cache state backend. Guarantees that files will always be A very safe image cache backend. Guarantees that files will always be
available, but at the cost of hitting the storage backend. available, but at the cost of hitting the storage backend.
""" """
@ -30,7 +30,7 @@ class PessimisticCacheStateBackend(object):
file.delete(save=False) file.delete(save=False)
class NonValidatingCacheStateBackend(object): class NonValidatingImageCacheBackend(object):
""" """
A backend that is super optimistic about the existence of spec files. It A backend that is super optimistic about the existence of spec files. It
will hit your file storage much less frequently than the pessimistic will hit your file storage much less frequently than the pessimistic
@ -41,7 +41,7 @@ class NonValidatingCacheStateBackend(object):
def validate(self, file): def validate(self, file):
""" """
NonValidatingCacheStateBackend has faith, so validate's a no-op. NonValidatingImageCacheBackend has faith, so validate's a no-op.
""" """
pass pass
@ -57,31 +57,31 @@ class NonValidatingCacheStateBackend(object):
file.delete(save=False) file.delete(save=False)
_default_cache_state_backend = None _default_image_cache_backend = None
def get_default_cache_state_backend(): def get_default_image_cache_backend():
""" """
Get the default cache state backend. Uses the same method as Get the default image cache backend. Uses the same method as
django.core.file.storage.get_storage_class django.core.file.storage.get_storage_class
""" """
global _default_cache_state_backend global _default_image_cache_backend
if not _default_cache_state_backend: if not _default_image_cache_backend:
from ..settings import DEFAULT_CACHE_STATE_BACKEND as import_path from .settings import DEFAULT_IMAGE_CACHE_BACKEND as import_path
try: try:
dot = import_path.rindex('.') dot = import_path.rindex('.')
except ValueError: except ValueError:
raise ImproperlyConfigured("%s isn't a cache state backend module." % \ raise ImproperlyConfigured("%s isn't an image cache backend module." % \
import_path) import_path)
module, classname = import_path[:dot], import_path[dot+1:] module, classname = import_path[:dot], import_path[dot+1:]
try: try:
mod = import_module(module) mod = import_module(module)
except ImportError, e: except ImportError, e:
raise ImproperlyConfigured('Error importing cache state module %s: "%s"' % (module, e)) raise ImproperlyConfigured('Error importing image cache backend module %s: "%s"' % (module, e))
try: try:
cls = getattr(mod, classname) cls = getattr(mod, classname)
_default_cache_state_backend = cls() _default_image_cache_backend = cls()
except AttributeError: except AttributeError:
raise ImproperlyConfigured('Cache state backend module "%s" does not define a "%s" class.' % (module, classname)) raise ImproperlyConfigured('Image cache backend module "%s" does not define a "%s" class.' % (module, classname))
return _default_cache_state_backend return _default_image_cache_backend

View file

@ -12,7 +12,7 @@ from imagekit.utils import img_to_fobj, open_image, \
format_to_extension, extension_to_format, UnknownFormatError, \ format_to_extension, extension_to_format, UnknownFormatError, \
UnknownExtensionError UnknownExtensionError
from imagekit.processors import ProcessorPipeline, AutoConvert from imagekit.processors import ProcessorPipeline, AutoConvert
from .cachestate import get_default_cache_state_backend from .imagecache import get_default_image_cache_backend
class _ImageSpecMixin(object): class _ImageSpecMixin(object):
@ -64,7 +64,7 @@ class ImageSpec(_ImageSpecMixin):
def __init__(self, processors=None, format=None, options={}, def __init__(self, processors=None, format=None, options={},
image_field=None, pre_cache=None, storage=None, cache_to=None, image_field=None, pre_cache=None, storage=None, cache_to=None,
autoconvert=True, cache_state_backend=None): autoconvert=True, image_cache_backend=None):
""" """
:param processors: A list of processors to run on the original image. :param processors: A list of processors to run on the original image.
:param format: The format of the output file. If not provided, :param format: The format of the output file. If not provided,
@ -96,9 +96,9 @@ class ImageSpec(_ImageSpecMixin):
this extension, it's only a recommendation. this extension, it's only a recommendation.
:param autoconvert: Specifies whether the AutoConvert processor :param autoconvert: Specifies whether the AutoConvert processor
should be run before saving. should be run before saving.
:param cache_state_backend: An object responsible for managing the state :param image_cache_backend: An object responsible for managing the state
of cached files. Defaults to an instance of of cached files. Defaults to an instance of
IMAGEKIT_DEFAULT_CACHE_STATE_BACKEND IMAGEKIT_DEFAULT_IMAGE_CACHE_BACKEND
""" """
@ -112,8 +112,8 @@ class ImageSpec(_ImageSpecMixin):
self.pre_cache = pre_cache self.pre_cache = pre_cache
self.storage = storage self.storage = storage
self.cache_to = cache_to self.cache_to = cache_to
self.cache_state_backend = cache_state_backend or \ self.image_cache_backend = image_cache_backend or \
get_default_cache_state_backend() get_default_image_cache_backend()
def contribute_to_class(self, cls, name): def contribute_to_class(self, cls, name):
setattr(cls, name, _ImageSpecDescriptor(self, name)) setattr(cls, name, _ImageSpecDescriptor(self, name))
@ -133,9 +133,9 @@ class ImageSpec(_ImageSpecMixin):
post_delete.connect(ImageSpec._post_delete_receiver, sender=cls, post_delete.connect(ImageSpec._post_delete_receiver, sender=cls,
dispatch_uid=uid) dispatch_uid=uid)
# Register the field with the cache_state_backend # Register the field with the image_cache_backend
try: try:
self.cache_state_backend.register_field(cls, self, name) self.image_cache_backend.register_field(cls, self, name)
except AttributeError: except AttributeError:
pass pass
@ -264,13 +264,13 @@ class ImageSpecFile(_ImageSpecFileMixin, ImageFieldFile):
file = property(_get_file, ImageFieldFile._set_file, ImageFieldFile._del_file) file = property(_get_file, ImageFieldFile._set_file, ImageFieldFile._del_file)
def clear(self): def clear(self):
return self.field.cache_state_backend.clear(self) return self.field.image_cache_backend.clear(self)
def invalidate(self): def invalidate(self):
return self.field.cache_state_backend.invalidate(self) return self.field.image_cache_backend.invalidate(self)
def validate(self): def validate(self):
return self.field.cache_state_backend.validate(self) return self.field.image_cache_backend.validate(self)
def generate(self, save=True): def generate(self, save=True):
""" """

View file

@ -1,5 +1,5 @@
from django.conf import settings from django.conf import settings
DEFAULT_CACHE_STATE_BACKEND = getattr(settings, DEFAULT_IMAGE_CACHE_BACKEND = getattr(settings,
'IMAGEKIT_DEFAULT_CACHE_STATE_BACKEND', 'IMAGEKIT_DEFAULT_IMAGE_CACHE_BACKEND',
'imagekit.cachestate.PessimisticCacheStateBackend') 'imagekit.imagecache.PessimisticImageCacheBackend')