Ejemplo n.º 1
0
def build_news_feed(sender, instance, **kwargs):
    """
    Build a static version of the news feed when a LibNewsPage is
    published or unpublished. Query the Django Rest Framework
    (Wagtail v2 API) and save the results to a static JSON file
    in the static files directory.

    Args:
        sender: LibNewsPage class

        instance: LibNewsPage instance

    Returns:
        None but writes a file to the static directory
    """
    clear_cache()
    cache.delete('news_cats')
    drf_url = instance.get_site().root_url + DRF_NEWS_FEED
    try:
        serialized_data = urlopen(drf_url).read()
        data = json.loads(serialized_data)
        with open(STATIC_NEWS_FEED, 'w', encoding='utf-8') as f:
            json.dump(data, f, ensure_ascii=False, indent=None)
    except (URLError):
        # We are running unit tests
        return None
Ejemplo n.º 2
0
    def test_clear_cache(self):
        # First get should miss cache.
        self.get_miss(self.page_cachedpage.get_url())
        # Second get should hit cache.
        self.get_hit(self.page_cachedpage.get_url())

        # clear all from Cache
        clear_cache()

        # Now the page should miss cache.
        self.get_miss(self.page_cachedpage.get_url())

        # Purge specific Url
        self.get_hit(self.page_cachedpage.get_url())
        self.get_miss(self.page_cachedpage.get_url() + "?action=pytest")

        url_from_keyring = next(iter(self.cache.get("keyring")))

        clear_cache([url_from_keyring + r"(?:\?|$)"])

        # Check if keyring is not present
        self.assertEqual(self.cache.get("keyring"), None)

        # Now the page should miss cache.
        self.get_miss(self.page_cachedpage.get_url())
Ejemplo n.º 3
0
 def tearDown(self):
     # Clear the cache and log out between each test.
     clear_cache()
     self.client.logout()
     # Delete any hooks.
     try:
         del hooks._hooks["is_request_cacheable"]
     except KeyError:
         pass
     try:
         del hooks._hooks["is_response_cacheable"]
     except KeyError:
         pass
Ejemplo n.º 4
0
def clear_wagtailcache(request, page):
    if page.live:
        clear_cache()
Ejemplo n.º 5
0
def clear(request):
    """
    AJAX call to clear the cache.
    """
    clear_cache()
    return HttpResponse(_("Cache has been cleared."))
Ejemplo n.º 6
0
def clear_wagtailcache(request, page):
    invalidate_all()
    if page.live:
        clear_cache()
Ejemplo n.º 7
0
def clear_wagtailcache(*args, **kwargs):
    clear_cache()
Ejemplo n.º 8
0
 def handle(self, *args, **options):
     clear_cache()