def clear_cache(objects=None, models=None, purge=False):
    # this is required to refresh the templates content
    # otherwise after any update the page will not refresh properly
    try:
        cache.clear()
    except Exception as e:
        # ignore errors
        logger.error(str(e))

    if _is_cacheops_enabled():
        from cacheops import invalidate_all, invalidate_model, invalidate_obj

        if objects:
            for obj in objects:
                invalidate_obj(obj)

        if models:
            for model in models:
                get_content_type(model=model)  # add it to the models list
                invalidate_model(model)

        if purge:
            try:
                invalidate_all()
            except Exception as e:
                # Fixes: unknown command `FLUSHDB`
                #   In helm charts FLUSHDB and FLUSHALL commands are disabled
                logger.error(str(e))
                clear_cache(models=list(CONTENT_TYPE_CACHE.keys()))
Exemple #2
0
def cache_view(request):
    if request.method == "POST":
        if "invalidate_all" in request.POST:
            invalidate_all()
            messages.success(request, "Invalidated all of the cache")

    try:
        opts = settings.CACHEOPS
        default = settings.CACHEOPS_DEFAULTS
    except AttributeError:
        opts = default = None

    cache = {}
    if opts:
        for ctype in opts:
            c = ctype.split(".", 1)[0]
            if "timeout" in opts[ctype]:
                to = opts[ctype]["timeout"]
            else:
                to = default["timeout"]
            cache[c] = int(to / (60 * 60))

    context = {
        "admin_page_title": "Cache Configuration",
        "cache_length": cache
    }
    return render(request, "eighth/admin/cache.html", context)
    def test_invalidation_signal(self):
        def set_signal(signal=None, **kwargs):
            signal_calls.append(kwargs)

        signal_calls = []
        cache_invalidated.connect(set_signal, dispatch_uid=1, weak=False)

        invalidate_all()
        invalidate_model(Post)
        c = Category.objects.create(title='Hey')
        self.assertEqual(signal_calls, [
            {
                'sender': None,
                'obj_dict': None
            },
            {
                'sender': Post,
                'obj_dict': None
            },
            {
                'sender': Category,
                'obj_dict': {
                    'id': c.pk,
                    'title': 'Hey'
                }
            },
        ])
Exemple #4
0
def cache_view(request):
    if request.method == "POST":
        if "invalidate_all" in request.POST:
            invalidate_all()
            messages.success(request, "Invalidated all of the cache")

    try:
        opts = settings.CACHEOPS
        default = settings.CACHEOPS_DEFAULTS
    except AttributeError:
        opts = default = None

    cache = {}

    for ctype in opts:
        c = ctype.split(".")[0]
        if "timeout" in opts[ctype]:
            to = opts[ctype]["timeout"]
        else:
            to = default["timeout"]
        cache[c] = int(to / (60 * 60))

    context = {
        "admin_page_title": "Cache Configuration",
        "cache_length": cache
    }
    return render(request, "eighth/admin/cache.html", context)
Exemple #5
0
    def setUp(self):
        # Emulate not being in transaction by tricking system to ignore its pretest level.
        # TestCase wraps each test into 1 or 2 transaction(s) altering cacheops behavior.
        # The alternative is using TransactionTestCase, which is 10x slow.
        transaction_state._stack, self._stack = [], transaction_state._stack

        invalidate_all()
Exemple #6
0
    def setUp(self):
        # Emulate not being in transaction by tricking system to ignore its pretest level.
        # TestCase wraps each test into 1 or 2 transaction(s) altering cacheops behavior.
        # The alternative is using TransactionTestCase, which is 10x slow.
        transaction_state._stack, self._stack = [], transaction_state._stack

        invalidate_all()
Exemple #7
0
    def handle(self, *args, **options):
        df = DatabaseFiller()
        # df.reset_increment_counter('auth_group')
        dashboard = options["dashboard"]
        formula = options["formula"]
        if options["clean"] or options["recreate"]:
            stdout_logger.info("INVALIDATE THAT F*****G SUKABLYAT' CACHE")
            invalidate_all()

        if options["create"] or options["recreate"]:
            stdout_logger.info("Creating db")

            stdout_logger.info("Creating superuser...")
            df.create_superuser()
            stdout_logger.info("Adding permissions...")
            df.create_permissions_and_groups()

            stdout_logger.info("Adding Employees...")
            df.fill_employees()

            stdout_logger.info("Adding plants...")
            df.fill_plants()

            stdout_logger.info("Create BL...")
            df.bl_create()
            df.fill_dicts()
            df.tasks_create()

            stdout_logger.info("Decompress Journals...")
            decompress_journals()

            stdout_logger.info("Adding groups...")
            df.create_number_of_shifts()
            df.create_groups()

            stdout_logger.info("Adding settings...")
            # df.create_journals_verbose_names()
            # df.create_tables_verbose_names()
            df.create_modes()

            # df.create_fields_descriptions()

            # stdout_logger.info("Adding journals...")
            # df.fill_journals()
            # stdout_logger.info("Adding tables...")
            # df.fill_tables()
            # stdout_logger.info("Adding fields...")
            # df.fill_fields()

            if dashboard:
                stdout_logger.info("Adding sample dashboard data...")
                df.create_dashboard_sample_data()

            if formula:
                stdout_logger.info("Adding sample formula data...")
                df.create_formula_sample_data()

            stdout_logger.info("Done!")
Exemple #8
0
def clear_models_cache(request=None):
    """ Call :mod:`cacheops`'s :func:`invalidate_all`. """

    # invalidate_obj(some_article)
    # invalidate_model(Article)
    invalidate_all()

    admin_message(request, 'info',
                  _(u'Cleared models cache (no detail available).'))
def clear_models_cache(request=None):
    """ Call :mod:`cacheops`'s :func:`invalidate_all`. """

    # invalidate_obj(some_article)
    # invalidate_model(Article)
    invalidate_all()

    admin_message(request, 'info',
                  _(u'Cleared models cache (no detail available).'))
Exemple #10
0
    def test_invalidation_signal(self):
        def set_signal(signal=None, **kwargs):
            signal_calls.append(kwargs)

        signal_calls = []
        cache_invalidated.connect(set_signal, dispatch_uid=1, weak=False)

        invalidate_all()
        invalidate_model(Post)
        c = Category.objects.create(title='Hey')
        self.assertEqual(signal_calls, [
            {'sender': None, 'obj_dict': None},
            {'sender': Post, 'obj_dict': None},
            {'sender': Category, 'obj_dict': {'id': c.pk, 'title': 'Hey'}},
        ])
Exemple #11
0
 def setUp(self):
     super(BaseTestCase, self).setUp()
     invalidate_all()
Exemple #12
0
def flush_cache():
    """delete all cached data"""
    cache.clear()
    invalidate_all()
Exemple #13
0
def flush_cache(request):
    cache.clear()
    invalidate_all()
    messages.success(request, "cache successful flushed!")
    return redirect(resolve_url("productdb_config:status"))
Exemple #14
0
def flush_cache():
    """delete all cached data"""
    cache.clear()
    invalidate_all()
Exemple #15
0
 def invalidate_cache(request):
     # Invalidate Cache
     invalidate_all()
     return HttpResponse("Cache invalidated")
Exemple #16
0
def clear_wagtailcache(request, page):
    invalidate_all()
    if page.live:
        clear_cache()
Exemple #17
0
 def setUp(self):
     super(BaseTestCase, self).setUp()
     invalidate_all()
     print('\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\invalidation done///////////////////////////////////////////////')
Exemple #18
0
import pymysql
from allauth.account.models import EmailAddress, EmailConfirmation
import datetime
from django.conf import settings
from django.utils.timezone import get_default_timezone
from main.helper import make_alias
from django.contrib.redirects.models import Redirect
from django.db.models import Q
from django.utils.html import strip_tags
from django.contrib.sites.models import Site
from allauth.socialaccount.models import SocialApp
from django.core.cache import cache
from cacheops import invalidate_all
from django.db.models.aggregates import Max

invalidate_all()
cache.clear()

tz = get_default_timezone()
def date_from_timestamp(ts):
    if not ts:
        return None
    else:
        return datetime.datetime.fromtimestamp(ts, tz)


def date_from_string(date):
    #year = date[:4]
    #month = date[5:7]
    #day = date[8:10]
    #hour = date[11:13]
Exemple #19
0
 def setUp(self):
     super(BaseTestCase, self).setUp()
     invalidate_all()
Exemple #20
0
def flush_cache(request):
    cache.clear()
    invalidate_all()
    messages.success(request, "cache successful flushed!")
    return redirect(resolve_url("productdb_config:status"))