Hi list,

I'm using Django as a hub to synchronize data between various external systems. 
To do this, I have some long-running Django management commands that are 
started as cron jobs. To ensure that only one job is working on a data set at 
any one time, I have implemented a locking system using the Django cache system.

Due to my less-than-stellar programming talent, a cron job may need to be 
killed once in a while. To avoid leaving orphaned locks in the cache, I want to 
clean up any locks before exiting, and I may not know which cache keys exist at 
the time of exit. Therefore, I want to write a signal handler that searches the 
Django cache for any entries that can be traced to the current process (my 
cache keys can be used for this purpose) and delete those.

AFAICS, the Django cache API can't be used for this. There's cache.clear() but 
I don't want to delete all cache entries. I'm using the database backend, so 
I'm thinking I could access the database table directly and issue any custom 
SQL on that. But it does feel hackish, so maybe one of you have a better 
approach? Maybe I got the whole thing backwards?

Here's my cache setup from settings.py:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
        'LOCATION': 'dispatch_cache',
        'TIMEOUT': None,
    }
}


Thanks,
Erik

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9A6110DB-9D5A-4A3F-9DD3-49CC406C1C18%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to