johnny cache django caching framework

Related tags

Caching johnny-cache
Overview
https://travis-ci.org/jmoiron/johnny-cache.png https://coveralls.io/repos/jmoiron/johnny-cache/badge.png

Johnny Cache is a caching framework for django applications. It works with the django caching abstraction, but was developed specifically with the use of memcached in mind. Its main feature is a patch on Django's ORM that automatically caches all reads in a consistent manner.

You can install johnny with pip:

pip install johnny-cache

You can fork johnny-cache from its git repository:

git clone http://github.com/jmoiron/johnny-cache.git

Or if you prefer mercurial, from its hg mirror:

hg clone http://bitbucket.org/jmoiron/johnny-cache

Please read The full documentation to Johnny Cache before using it.

Comments
  • Python 3 support, Travis CI & a few modernisations

    Python 3 support, Travis CI & a few modernisations

    In order to achieve johnny-cache 1.5 goals, I made the following:

    • I added Travis CI to smoothly move from 1.4 to 1.5, but discovered that johnny-cache was not able to run with Django 1.1 (and Python 2.4 & 2.5 are not available on Travis CI)
    • so I wanted to speed things a bit. I implemented full Python 3 support and decided to drop Django<1.3 & Python<2.6 support (as specified in the 1.5 goals).
    • in tests, I changed old failUnless etc to assertTrue, assertFalse, assertEqual and assertNotEqual, all supported from Python 2.6
    • I started working on Django 1.6 support, and only pushed a backward-compatible version of #36. I still have lots of pending changes on my computer about this, but the test suite still fails so I'll stick to this bunch of changes for today.
    opened by BertrandBordage 11
  • Strange errors

    Strange errors

    Hi,

    I'm relatively new to Johnny Cache and memcached so maybe it's a simple problem, but I have a report app that is giving me problems. For 2011, for example, I have 14 teams on the landing page. Clicking on most work fine, but one always has this error:

    MemcachedError at /nai/reports/annual-reports/2011/gsfc/
    error 37 from memcached_set: SYSTEM ERROR(Resource temporarily unavailable), host: 127.0.0.1:11211 -> libmemcached/io.cc:358
    

    I'm wondering if it's something to do with my version of memcached on my server.

    I'm running Ubuntu. Can you tell me what the best version of memcached to use?

    Also, I'm using pylibmc==1.2.3

    Thanks.

    opened by typeshige 7
  • Is Johnny Cache compatible with PostgreSQL autocommit?

    Is Johnny Cache compatible with PostgreSQL autocommit?

    The docs explain that this is a tricky part: http://pythonhosted.org/johnny-cache/queryset_cache.html#transactions

    But I am struggling to understand if autocommit causes any issues for Johnny? Or does it make Johnny's life easier?

    opened by AudriusButkevicius 5
  • Strange issues with caches not being invalidated and getting

    Strange issues with caches not being invalidated and getting "stuck"

    We're using johnny cache in a multi-web server environment and we're running into some strange issues in which query caches aren't being invalidated. Unfortunately, we haven't been able to figure out how to reproduce it though it does happen consistently.

    We're set up at EC2 and we have 2 web servers set up using nginx + uwsgi. We're only using one db (pooled using pgbouncer on each webserver) and have johnny cache configured to use the memcached backend with ElastiCache.

    Most of our code uses Django's default autocommit mode but we do have some methods where we use the @transaction.commit_on_success decorator.

    We also have some cron jobs (set up using django-cronjobs) which we run and which need to invalidate caches. In the methods for those cron jobs, we call johhn.cache.enable() to set up johnny cache before we do any other work.

    The scenario below works sometimes but then stops working after some time. Once it stops working, we can manually invalidate the object's cache and it starts working again or we can cycle uwsgi on the webservers which also gets things working again.

    1. Create a new MyObject (via a form that is saved)
    2. In the cronjob, get a list of all MyObjects

    Step 2 is what stops working in the sense that new MyObjects don't show up in the list.

    We've spent hours trying to track this down so any help you can provide would be great!

    opened by tesh11 5
  • MemcachedError in Admin

    MemcachedError in Admin

    Hi,

    Using Django 1.4 and in admin I have a model that I can't see the detail view.

    MemcachedError at /admin/nims/article/1141/
    error 37 from memcached_set: SYSTEM ERROR(Resource temporarily unavailable), host: 127.0.0.1:11211 -> libmemcached/io.cc:358
    Request Method: GET
    Request URL:    http://127.0.0.1:8007/admin/nims/article/1141/
    Django Version: 1.4
    Exception Type: MemcachedError
    Exception Value:    
    error 37 from memcached_set: SYSTEM ERROR(Resource temporarily unavailable), host: 127.0.0.1:11211 -> libmemcached/io.cc:358
    Exception Location: /home/django/.virtualenvs/astrobiology-alpha/local/lib/python2.7/site-packages/django/core/cache/backends/memcached.py in set, line 64
    Python Executable:  /home/django/.virtualenvs/astrobiology-alpha/bin/python
    Python Version: 2.7.1
    

    Most of my admin works, my guess is this article model is quite a big bigger than the others..

    Please let me know how to debug this and if I can send you anything else that would be useful.

    Thanks, Shige

    opened by typeshige 5
  • Globally enabling Johnny Cache in __init__.py causes error with syncdb

    Globally enabling Johnny Cache in __init__.py causes error with syncdb

    AttributeError: 'module' object has no attribute 'empty_iter'

    Solution:

    import sys
    try:
        if sys.argv[1] != 'syncdb':
            raise Exception
    except:
        from johnny.cache import enable
        enable()
    
    opened by radiosilence 3
  • Fixed bug that caused KeyError in _commit_all_savepoints

    Fixed bug that caused KeyError in _commit_all_savepoints

    Fixed bug that caused KeyError in johnny.transaction.TransactionManager._commit_all_savepoints - issues #26 and #30 on Github (#69 on Bitbucket)

    This patch is fixing cause of the problem, not hiding it as pull requests #26 and #30.

    To reproduce cause of the problem you should:

    1. Enable QueryCacheMiddleware
    2. Work in unmanaged transaction state (it means autocommit mode, i.e. without django.middleware.transaction.TransactionMiddleware and not within transaction.enter_transaction_management() block)
    3. Create a savepoint and then try to save some object (it is done by django.db.models.query.QuerySet#get_or_create or by django.contrib.sessions.backends.db.SessionStore#save)

    The essence of the problem is the fact that Django ORM widely uses a django/db/transaction.py#commit_unless_managed (which is unpatched by Johny Cache) function instead of django/db/transaction.py#commit (which is patched by Johny Cache). So, when we working in unmanaged transaction state Johny Cache will still register savepoints upon creation but will be unable to handle commits and rollbacks that wast performed by 'unless_managed' functions. Since Django is using dumb algorithm for savepoint names generation (they reuse same names within thread once they were commited) it will lead to a situation when Johny Cache will register several savepoints with same name within one transaction and fail when it will try to commit or rollback them.

    Proposed solution adds patching to django/db/transaction.py#commit_unless_managed and django/db/transaction.py#rollback_unless_managed functions in the same way as it was done for django/db/transaction.py#commit and django/db/transaction.py#rollback functions with one difference - additional check whether current transaction is unmanaged.

    opened by ashald 3
  • johnny-cache doesn't update cache after update data from manage.py command.

    johnny-cache doesn't update cache after update data from manage.py command.

    I use some manage.py command to parse and upload some data to my database. johnny-cache cached my data once and after updates my data cache doesn't update. In database I have actual data, but my site show old data from cache.

    I have to restart my memcached server to solve that problem after each data update. Anyone has similar problem?

    opened by inlanger 3
  • SECRET_KEY published

    SECRET_KEY published

    @jmoiron it seems that you've published your SECRET_KEY in settings.py.

    Here are the details:

    https://www.quantifiedcode.com/app#/project/gh:jmoiron:johnny-cache?groups=code_patterns%3A1Wit6MHp%3Af0

    opened by adewes 2
  • Use sets rather than lists when getting tables for query.

    Use sets rather than lists when getting tables for query.

    johnny.cache.get_tables_for_query_pre_16: use a set as the base tables collection before entering recursion, thus avoiding a MemoryError should the WHERE descendant list go too deep.

    This fully fixes #45 by preventing the top-most table list from growing more than it has to by being a set.

    We ran into this problem because we had a bug that built a bad query. The query was valid, but the app broke when johnny-cache was in use.

    opened by radicalbiscuit 2
  • celery_enable_all clarification

    celery_enable_all clarification

    I see the johnny.utils.celery_enable_all function, but it is not clear where it should be called from.

    I see this same question posted on the (old?) bitbucket repo too in issue 47 but it was never answered.

    Any clarification would be much appreciated.

    opened by hassa 2
  • Bump django from 1.4 to 2.2.24 in /docs

    Bump django from 1.4 to 2.2.24 in /docs

    Bumps django from 1.4 to 2.2.24.

    Commits
    • 2da029d [2.2.x] Bumped version for 2.2.24 release.
    • f27c38a [2.2.x] Fixed CVE-2021-33571 -- Prevented leading zeros in IPv4 addresses.
    • 053cc95 [2.2.x] Fixed CVE-2021-33203 -- Fixed potential path-traversal via admindocs'...
    • 6229d87 [2.2.x] Confirmed release date for Django 2.2.24.
    • f163ad5 [2.2.x] Added stub release notes and date for Django 2.2.24.
    • bed1755 [2.2.x] Changed IRC references to Libera.Chat.
    • 63f0d7a [2.2.x] Refs #32718 -- Fixed file_storage.test_generate_filename and model_fi...
    • 5fe4970 [2.2.x] Post-release version bump.
    • 61f814f [2.2.x] Bumped version for 2.2.23 release.
    • b8ecb06 [2.2.x] Fixed #32718 -- Relaxed file name validation in FileField.
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • ORA-22922: nonexistent LOB value during loading of data in a transaction

    ORA-22922: nonexistent LOB value during loading of data in a transaction

    I get the following error when trying to deserialize django data and only with cache enabled. (Johnny cache 1.4, Django 1.4.18)

    Traceback (most recent call last):
      File "/opt/tangram/tangramdt/tangram_base/src/tangram/apps/api/deploy.py", line 285, in import_process_def
        transaction.commit()
      File "/opt/tangram/tangramdt/buildout/eggs/johnny_cache-1.4-py2.7.egg/johnny/transaction.py", line 145, in newfun
        self._flush(commit=commit, using=using)
      File "/opt/tangram/tangramdt/buildout/eggs/johnny_cache-1.4-py2.7.egg/johnny/transaction.py", line 133, in _flush
        self.cache_backend.set(key, value, self.timeout)
      File "/opt/tangram/tangramdt/buildout/eggs/Django-1.4.18-py2.7.egg/django/core/cache/backends/memcached.py", line 64, in set
        self._cache.set(key, value, self._get_memcache_timeout(timeout))
      File "/opt/tangram/tangramdt/buildout/eggs/python_memcached-1.48-py2.7.egg/memcache.py", line 565, in set
        return self._set("set", key, val, time, min_compress_len)
      File "/opt/tangram/tangramdt/buildout/eggs/python_memcached-1.48-py2.7.egg/memcache.py", line 802, in _set
        return _unsafe_set()
      File "/opt/tangram/tangramdt/buildout/eggs/python_memcached-1.48-py2.7.egg/memcache.py", line 780, in _unsafe_set
        store_info = self._val_to_store_info(val, min_compress_len)
      File "/opt/tangram/tangramdt/buildout/eggs/python_memcached-1.48-py2.7.egg/memcache.py", line 751, in _val_to_store_info
        pickler.dump(val)
    DatabaseError: ORA-22922: nonexistent LOB value
    

    As a workaround I surround it with a cache.disable() / cache.enable()

    opened by erny 0
  • SqlDateCompiler is removed in django 1.8

    SqlDateCompiler is removed in django 1.8

    Django 1.8 no longer has the class SqlDateCompiler, so we might have to modify the code to accommodate that.

    https://github.com/jmoiron/johnny-cache/blob/master/johnny/cache.py#L412

    opened by karthikbgl 1
Owner
Jason Moiron
Jason Moiron
Python disk-backed cache (Django-compatible). Faster than Redis and Memcached. Pure-Python.

DiskCache is an Apache2 licensed disk and file backed cache library, written in pure-Python, and compatible with Django.

Grant Jenks 1.7k Jan 5, 2023
An ORM cache for Django.

Django ORMCache A cache manager mixin that provides some caching of objects for the ORM. Installation / Setup / Usage TODO Testing Run the tests with:

Educreations, Inc 15 Nov 27, 2022
A Redis cache backend for django

Redis Django Cache Backend A Redis cache backend for Django Docs can be found at http://django-redis-cache.readthedocs.org/en/latest/. Changelog 3.0.0

Sean Bleier 1k Dec 15, 2022
WSGI middleware for sessions and caching

Cache and Session Library About Beaker is a web session and general caching library that includes WSGI middleware for use in web applications. As a ge

Ben Bangert 500 Dec 29, 2022
A caching extension for Flask

Flask-Caching Adds easy cache support to Flask. This is a fork of the Flask-Cache extension. Flask-Caching also includes the cache module from werkzeu

Peter Justin 774 Jan 2, 2023
Simple caching transport for httpx

httpx-cache is yet another implementation/port is a port of the caching algorithms in httplib2 for use with httpx Transport object.

Ouail 28 Jan 1, 2023
Aircache is an open-source caching and security solution that can be integrated with most decoupled apps that use REST APIs for communicating.

AirCache Aircache is an open-source caching and security solution that can be integrated with most decoupled apps that use REST APIs for communicating

AirCache 2 Dec 22, 2021
A slick ORM cache with automatic granular event-driven invalidation.

Cacheops A slick app that supports automatic or manual queryset caching and automatic granular event-driven invalidation. It uses redis as backend for

Alexander Schepanovski 1.7k Dec 30, 2022
Automatic Flask cache configuration on Heroku.

flask-heroku-cacheify Automatic Flask cache configuration on Heroku. Purpose Configuring your cache on Heroku can be a time sink. There are lots of di

Randall Degges 39 Jun 5, 2022
RecRoom Library Cache Tool

RecRoom Library Cache Tool A handy tool to deal with the Library cache file. Features Parse Library cache Remove Library cache Parsing The script pars

Jesse 5 Jul 9, 2022
Peerix is a peer-to-peer binary cache for nix derivations

Peerix Peerix is a peer-to-peer binary cache for nix derivations. Every participating node can pull derivations from each other instances' respective

null 92 Dec 13, 2022
Robust, highly tunable and easy-to-integrate in-memory cache solution written in pure Python, with no dependencies.

Omoide Cache Caching doesn't need to be hard anymore. With just a few lines of code Omoide Cache will instantly bring your Python services to the next

Leo Ertuna 2 Aug 14, 2022
An implementation of memoization technique for Django

django-memoize django-memoize is an implementation of memoization technique for Django. You can think of it as a cache for function or method results.

Unhaggle 118 Dec 9, 2022
Django package to log request values such as device, IP address, user CPU time, system CPU time, No of queries, SQL time, no of cache calls, missing, setting data cache calls for a particular URL with a basic UI.

django-web-profiler's documentation: Introduction: django-web-profiler is a django profiling tool which logs, stores debug toolbar statistics and also

MicroPyramid 77 Oct 29, 2022
Cache-house - Caching tool for python, working with Redis single instance and Redis cluster mode

Caching tool for python, working with Redis single instance and Redis cluster mo

Tural 14 Jan 6, 2022
Jira-cache - Jira cache with python

Direct queries to Jira have two issues: they are sloooooow many queries are impo

John Scott 6 Oct 8, 2022
Automatic caching and invalidation for Django models through the ORM.

Cache Machine Cache Machine provides automatic caching and invalidation for Django models through the ORM. For full docs, see https://cache-machine.re

null 846 Nov 26, 2022
Automatic caching and invalidation for Django models through the ORM.

Cache Machine Cache Machine provides automatic caching and invalidation for Django models through the ORM. For full docs, see https://cache-machine.re

null 846 Nov 26, 2022
Full featured redis cache backend for Django.

Redis cache backend for Django This is a Jazzband project. By contributing you agree to abide by the Contributor Code of Conduct and follow the guidel

Jazzband 2.5k Jan 3, 2023
A Redis cache backend for django

Redis Django Cache Backend A Redis cache backend for Django Docs can be found at http://django-redis-cache.readthedocs.org/en/latest/. Changelog 3.0.0

Sean Bleier 1k Dec 15, 2022