Permalink
Browse files

initial import

  • Loading branch information...
1 parent ac50870 commit 23e72a2af24dd7b671f14708bd8c0154bad68510 @justquick committed Dec 9, 2009
View
@@ -0,0 +1,25 @@
+Django Varnish
+================
+
+Varnish is a state-of-the-art, high-performance HTTP accelerator.
+For more information checkout `Varnish Site <http://varnish.projects.linpro.no/>`_
+
+Django Varnish works with Varnish server(s) to manage caching of object pages.
+It allows you to monitor certain models and when they are updated,
+Django Varnish will purge the model's absolute_url on your frontend(s).
+This ensures that object detail pages are served blazingly fast and are always up to date.
+You may also go in and manually tweak things (such as your VCL configuration) using a management command.
+
+Django Varnish requires the `varnish python bindings <http://github.com/justquick/python-varnish>`_
+
+Put ``varnishapp`` in your ``INSTALLED_APPS`` then set a few more settings.
+
+``VARNISH_WATCHED_MODELS`` is a list of installed models whose absolute_urls you want to purge from your
+Varnish cache upon saving. Example: ``('auth.user','profiles.profile')``
+
+``VARNISH_MANAGMENT_ADDRS`` is a list of Varnish cache addresses (containing their management ports).
+Example ``('server1:6082','server2:6082')``
+
+
+The management command ``varnishmgt`` is also now available and just blindly executes passes commands and prints the results.
+Example ``$ ./manage.py varnishmgt purge_url "/"``
View
@@ -0,0 +1,11 @@
+from distutils.core import setup
+
+setup(
+ name = "django-varnish",
+ version = '0.1',
+ url = 'http://opensource.washingtontimes.com/projects/django-varnish/',
+ author = 'Justin Quick',
+ description = 'Integration between Django and the Varnish HTTP accelerator using the management port using telnet',
+ packages = ['varnishapp']
+)
+
View
No changes.
No changes.
No changes.
@@ -0,0 +1,10 @@
+from django.core.management.base import BaseCommand
+from varnishapp.manager import manager
+from pprint import pprint
+
+class Command(BaseCommand):
+ def handle(self, *args, **options):
+ if args:
+ pprint(manager.run(*args))
+ else:
+ print manager.help()
View
@@ -0,0 +1,7 @@
+from varnish import VarnishManager
+from django.conf import settings
+from atexit import register
+
+
+manager = VarnishManager(*getattr(settings, 'VARNISH_MANAGMENT_ADDRS', ()))
+register(manager.close)
View
@@ -0,0 +1 @@
+manager = VarnishManager(*getattr(settings, 'VARNISH_MANAGMENT_ADDRS', ()))
View
@@ -0,0 +1,11 @@
+from django.db.models.signals import post_save
+from django.db.models import get_model
+from django.conf import settings
+from manager import manager
+
+
+def absolute_url_purge_handler(sender, **kwargs):
+ manager.run('purge.url', r'^%s$' % kwargs['instance'].get_absolute_url())
+
+for model in getattr(settings, 'VARNISH_WATCHED_MODELS', ()):
+ post_save.connect(absolute_url_purge_handler, sender=get_model(*model.split('.')))

0 comments on commit 23e72a2

Please sign in to comment.