Database Cache Management View

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from django.shortcuts import render_to_response
from django.core.urlresolvers import reverse
from django.contrib.admin.views.decorators import staff_member_required
from django.utils.translation import ugettext_lazy as _
from django.db import connection

CACHE_TABLE_OID = 69126

@staff_member_required
def admin_cache_management(request):
    cursor = connection.cursor()
    message = ""
    if request.POST:
    	cursor.execute("DELETE FROM django_cache")
    	cursor.execute("COMMIT")
    	cursor.execute("VACUUM FULL FREEZE ANALYZE django_cache")
    	message = _("A manual cache flush has been requested by an administrator, and was executed with success")
    	
    cursor.execute("""
    SELECT 
		pg_stat_get_numscans(%s),
		pg_stat_get_tuples_updated(%s),
		pg_stat_get_tuples_inserted(%s),
		pg_stat_get_tuples_deleted(%s),
		COUNT(*),
		pg_size_pretty(pg_total_relation_size('django_cache'))
	FROM django_cache;
    """, (CACHE_TABLE_OID, CACHE_TABLE_OID, CACHE_TABLE_OID, CACHE_TABLE_OID));
    data = cursor.fetchone()
    cache_hits = int(data[0])
    cache_updated = int(data[1])
    cache_inserted = int(data[2])
    cache_deleted = int(data[3])
    cache_entry_amount = int(data[4])
    cache_size = data[5]

    cursor.execute("COMMIT")
    return render_to_response("system/admin_cache_management.html", 
    {
    	"cache_entry_amount": cache_entry_amount,
    	"cache_size": cache_size,
    	"cache_hits": cache_hits,
    	"cache_updated": cache_updated,
    	"cache_inserted": cache_inserted,
    	"cache_deleted": cache_deleted,
    	"message": message,
    })

More like this

  1. Searching and Deleting Cache Entries in Admin tool by shootclub 2 years, 9 months ago
  2. Drop all tables in MySQL database by mpasternacki 4 years, 2 months ago
  3. Cached lookup model mixin by isagalaev 6 years, 3 months ago
  4. Cache Manager by jerzyk 6 years, 4 months ago
  5. Locking tables by miohtama 5 years, 9 months ago

Comments

(Forgotten your password?)