Beispiel #1
0
def invalidate_settings_cache(sender=None, instance=None, isnew=False, **kwargs):
    if isnew:
        return

    site_id = instance.site.id
    key = create_cache_key(Settings, field='site__id', field_value=site_id)
    cache.set(key, None, 5)
Beispiel #2
0
    def get_all():
        key = create_cache_key(ThirdPartySoftware, field='type', field_value='all')
        software_list = cache.get(key, None)

        if not software_list:
            try:
                software_list = ThirdPartySoftware.objects.all().order_by('name')
                cache.add(key, software_list)
            except Navigation.DoesNotExist:
                return None

        return software_list
Beispiel #3
0
    def get_navigation(name):
        key = create_cache_key(Navigation, field='name', field_value=name)
        navigation = cache.get(key, None)

        if not navigation:
            try:
                navigation = Navigation.objects.filter(name=name)[0]
                cache.add(key, navigation)
            except Navigation.DoesNotExist:
                return None

        return navigation
Beispiel #4
0
    def get_current():
        site = Site.objects.get_current()
        key = create_cache_key(Settings, field='site__id', field_value=site.id)
        settings = cache.get(key, None)

        if not settings:
            try:
                settings = Settings.objects.get(site=site)
                cache.add(key, settings)
            except Navigation.DoesNotExist:
                return None

        return settings
Beispiel #5
0
def _get_eyes(request, url):    
    cache_key = create_cache_key({"url": url, "type": "eyes"})
    
    # download image from internet
    api = ImageAPI()
    api.open_from_internet(url)
    
    # try to get from cache
    faces = cache.get(cache_key)
    if faces is not None:
        logger.debug("found faces in cache for %s" % url)
    else:
        # identify faces
        faces = detect_eyes_from_pil_image(api.image)
        
        # put on cache for 1h
        cache.set(cache_key, faces, 3600)
        
    return api, faces
Beispiel #6
0
def invalidate_thirdpartysoftware_cache(sender=None, instance=None, isnew=False, **kwargs):
    if isnew:
        return

    key = create_cache_key(ThirdPartySoftware, field='type', field_value='all')
    cache.set(key, None, 5)
Beispiel #7
0
def invalidate_navigation_cache(sender=None, instance=None, isnew=False, **kwargs):
    if isnew:
        return

    key = create_cache_key(Navigation, field='name', field_value=instance.name)
    cache.set(key, None, 5)