question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MemcachedKeyCharacterError

See original GitHub issue

Hi,

I am trying to use the @memoize decorator to cache a method in a view, with python-memcached present, like below:

class BlogView(generic.ListView, CoreBreadcrumbs):
    template_name = 'blog/blog.html'
    context_object_name = 'items'

    @memoize(timeout=3600)
    def get_paginate_by(self, queryset):
        return BlogSettings.objects.get().howmany_perpage
...

and I get the following error:

MemcachedKeyCharacterError: Control/space characters not allowed (key=':1:blog.views.BlogView.get_paginate_by.<blog.views.BlogView object at 0x03518AD0>_memver')

Full traceback - https://gist.github.com/DragosChirila/ce814ffd2a4d24e82c78c8cd013288e6

Am I doing something wrong here? Could you please advice?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
DragosChirilacommented, Apr 5, 2017

Thanks! Indeed, using something like

    def __repr__(self):
        """ Overwrite this for memcache key generation.
        """
        return '{}.{}'.format(self.__module__, self.__class__.__name__)

seems to work.

On the other hand, I tried to use the make_name parameter but without success. Do you have a working example with a custom make_name method?

0reactions
DragosChirilacommented, Apr 5, 2017

I did it like this:

    @memoize(timeout=3600, make_name=make_name_for_view)
    def get_paginate_by(self, queryset):
        return BlogSettings.objects.get().howmany_perpage

where

def make_name_for_view(name):
    return 'my custom name'

But, make_name_for_view never gets called.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Control/space characters not allowed · Issue #122 ... - GitHub
When trying to use this package with memcached, I get the following error: memcache.MemcachedKeyCharacterError: Control/space characters not allowed ...
Read more >
MemcachedKeyCharacterError: Control characters not allowed
MemcachedKeyCharacterError : Control characters not allowed. Bug #634646 reported by Curtis Hovey on 2010-09-10. 6. This bug affects 1 person ...
Read more >
Removing control/space characters from cache key in python
I have to remove control/space characters from my cache key. It is giving following error: MemcachedKeyCharacterError ...
Read more >
MemcachedKeyCharacterError at /api/search - Jira Atlassian
NOTE: This bug report is for Confluence Server. Using Confluence Cloud? See the corresponding bug report. Environment: Request Method: POST Request URL: http:// ......
Read more >
memcache.Client.MemcachedKeyCharacterError Example
python code examples for memcache.Client.MemcachedKeyCharacterError. Learn how to use python api memcache.Client.MemcachedKeyCharacterError.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found