hydra-cache


Namehydra-cache JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/iamharshdev/hydra_cache
SummaryA mixin that unleash the Kraken of DJANGO Caching Power
upload_time2024-05-25 06:56:29
maintainerNone
docs_urlNone
authorHarsh Vardhan Goswami
requires_python>=3.6
licenseNone
keywords
VCS
bugtrack_url
requirements asgiref Django sqlparse
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Hydra Cache: The Ultimate Solution for Taming the Caching Chaos

Yo, what's up my fellow Django devs? You know what really grinds my gears? Dealing with caching in web apps. It's like trying to catch a greased-up, naked guy in a pool of Vaseline. But fear not, my dudes, because Hydra Cache is here to save the day (and your sanity).

## The Legend

In the depths of web development lore, there lurks a terrifying creature known as the Kraken of Caching Complexity. This multi-headed monstrosity has been ensnaring developers in its tangled tentacles, leaving them adrift in a sea of stale data and suboptimal performance. But fear not, my brave memers oh devs sorry!, for Hydra Cache is here to slay this beast once and for all!

## Why I Built Hydra Cache

Look, I've been there, okay? I've spent countless nights battling this caching nightmare, writing the same boilerplate code over and over again, like some kind of masochistic ritual. But no more, my fellas! I created Hydra Cache to save you from this madness, so you can spend more time scrolling through lusty memes! Oops, ~just memes~

With Hydra Cache, you can:

- **Reduce Boilerplate Code**: No more copy-pasting the same caching logic across your views. Just inherit from `HydraCacheMixin`, and you're good to go, bruh!
- **Centralize Caching Configuration**: Kiss goodbye to the days of hunting down caching configurations scattered across your codebase. With Hydra Cache, you control it all from one central location, like a true meme lord.
- **Consistent Caching Patterns**: Consistency is key, my dudes. Hydra Cache ensures that your caching logic follows a standardized approach, making it easier for your team (and your future self) to understand and maintain, even after a night of binge-watching memes.
- **Flexible Cache Invalidation**: Stale data? Not on my watch! Hydra Cache automatically invalidates your cache after `POST`, `PUT`, `DELETE`, and `PATCH` requests, keeping your app fresher than a meme.
- **Fine-Grained Cache Clearing**: With the `match_on_cache_key` option, you can clear the cache with surgical precision, targeting specific keys and leaving the rest untouched. No more scorched-earth cache purging!
- **Easy Integration**: Hydra Cache plays nice with Django's built-in caching system, so you can leverage your existing cache backends without any extra hassle, just like how porn clips seamlessly integrate into your daily life! Not your ex!.

## Key Features

- **Cache Key Sorcery**: Weave intricate cache keys, summoning the power of timeouts and vary headers like a true caching wizard, but with the dankness of a meme lord.
- **Automatic Cache Purging**: Unleash the fury of automatic cache invalidation, cleansing your app of stale data with the force of a raging maelstrom, or a dank meme going viral.
- **Fine-Grained Cache Clearing**: Clear the cache with surgical precision, slicing through cache keys like a skilled samurai, or like a dank meme slicing through the internet.
- **Seamless Integration**: Harness the power of Django's caching system without breaking a sweat, just like how you effortlessly integrate memes into your conversations.
- **Extensible Might**: Customize and extend Hydra Cache to fit your twisted caching desires, like a mad scientist tinkering with an unholy creation, or a meme lord crafting the dankest memes.

## Getting Started

Alright, listen up, my fellow memers! Here's how you summon the Kraken of Caching Awesomeness:

1. Install the package like a true caching warrior: `pip install boring-hydra-cache`
2. In your Django views, import the `HydraCacheMixin` like you're summoning an ancient caching ritual: `from hydra_cache.mixins import HydraCacheMixin`
3. Create a view class that inherits from both `HydraCacheMixin` and your desired Django view class, binding the Kraken to your unholy will:

```python
from django.views.generic import APIView
from hydra_cache.mixins import HydraCacheMixin

class MyListView(HydraCacheMixin, APIView):
    cache_key_prefix = 'my_list_view'
    cache_timeout = 3600  # 1 hour
    vary_on_header = 'X-Requested-With'

```

1. In a scenario where you have two separate views - `MyListView` for listing data and `MyCreateUpdateView` for creating or updating data, you can use Hydra Cache to ensure that the cache for `MyListView` is cleared whenever new data is created, updated, or deleted.

First, ensure that both views inherit from `HydraCacheMixin`

In `MyCreateUpdateView`, you would set the `match_on_cache_key` attribute to `True` and list `my_list_view` in the `clear_cache_keys` attribute:

```python
class MyCreateUpdateView(HydraCacheMixin, APIView):
    ...
    match_on_cache_key = True
    clear_cache_keys = ['my_list_view']
    disable_cache = True
```

With this setup, any `POST`, `PUT`, `DELETE`, or `PATCH` request made through `MyCreateUpdateView` will automatically clear the cache for `MyListView`, ensuring that the list view always displays the most recent data.

And just like that, my friends, you've harnessed the power of Hydra Cache, commanding the multi-headed Kraken of Caching Awesomeness and charting a course towards unparalleled performance and scalability!

But wait, there's more! With Hydra Cache, you have the power to unleash the Kraken's fury upon your cache whenever you desire, like a true sucker. While the `HydraCacheMixin` automatically handles cache invalidation for `POST`, `PUT`, `DELETE`, and `PATCH` requests, you can also clear the cache independently within your model signals, custom commands, or any other part of your application.

Behold the mighty `flush_cache_for_keys` method, a potent incantation that summons the Kraken's wrath upon specific cache keys:

```python
from hydra_cache.utils import flush_cache_for_keys
```

For example, within a Django model signal, you could clear the cache for a specific object:

```python
from django.db.models.signals import post_save
from django.dispatch import receiver
from hydra_cache.utils import flush_cache_for_keys

@receiver(post_save, sender=MyModel)
def clear_my_model_cache(sender, instance, **kwargs):
    cache_key_prefix = f'my_model_{instance.pk}'
    flush_cache_for_keys(cache_key_prefix)

```

## Conclusion

Look, I get it. Caching can be a real pain in the neck, but with Hydra Cache, you can finally tame the beast and take control of your caching strategies. No more boilerplate code, no more scattered configurations, and no more stale data nightmares. Just pure, unadulterated caching awesomeness!

So what are you waiting for? Embrace the Kraken, and let the tides of caching ever be in your favor, my fellow meme lords!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/iamharshdev/hydra_cache",
    "name": "hydra-cache",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Harsh Vardhan Goswami",
    "author_email": "me@iamharsh.dev",
    "download_url": "https://files.pythonhosted.org/packages/90/c6/ab7daf8305a122866595cd41d32e736964e3e38303bd8f3136cd829326e7/hydra_cache-0.1.2.tar.gz",
    "platform": null,
    "description": "# Hydra Cache: The Ultimate Solution for Taming the Caching Chaos\n\nYo, what's up my fellow Django devs? You know what really grinds my gears? Dealing with caching in web apps. It's like trying to catch a greased-up, naked guy in a pool of Vaseline. But fear not, my dudes, because Hydra Cache is here to save the day (and your sanity).\n\n## The Legend\n\nIn the depths of web development lore, there lurks a terrifying creature known as the Kraken of Caching Complexity. This multi-headed monstrosity has been ensnaring developers in its tangled tentacles, leaving them adrift in a sea of stale data and suboptimal performance. But fear not, my brave memers oh devs sorry!, for Hydra Cache is here to slay this beast once and for all!\n\n## Why I Built Hydra Cache\n\nLook, I've been there, okay? I've spent countless nights battling this caching nightmare, writing the same boilerplate code over and over again, like some kind of masochistic ritual. But no more, my fellas! I created Hydra Cache to save you from this madness, so you can spend more time scrolling through lusty memes! Oops, ~just memes~\n\nWith Hydra Cache, you can:\n\n- **Reduce Boilerplate Code**: No more copy-pasting the same caching logic across your views. Just inherit from `HydraCacheMixin`, and you're good to go, bruh!\n- **Centralize Caching Configuration**: Kiss goodbye to the days of hunting down caching configurations scattered across your codebase. With Hydra Cache, you control it all from one central location, like a true meme lord.\n- **Consistent Caching Patterns**: Consistency is key, my dudes. Hydra Cache ensures that your caching logic follows a standardized approach, making it easier for your team (and your future self) to understand and maintain, even after a night of binge-watching memes.\n- **Flexible Cache Invalidation**: Stale data? Not on my watch! Hydra Cache automatically invalidates your cache after `POST`, `PUT`, `DELETE`, and `PATCH` requests, keeping your app fresher than a meme.\n- **Fine-Grained Cache Clearing**: With the `match_on_cache_key` option, you can clear the cache with surgical precision, targeting specific keys and leaving the rest untouched. No more scorched-earth cache purging!\n- **Easy Integration**: Hydra Cache plays nice with Django's built-in caching system, so you can leverage your existing cache backends without any extra hassle, just like how porn clips seamlessly integrate into your daily life! Not your ex!.\n\n## Key Features\n\n- **Cache Key Sorcery**: Weave intricate cache keys, summoning the power of timeouts and vary headers like a true caching wizard, but with the dankness of a meme lord.\n- **Automatic Cache Purging**: Unleash the fury of automatic cache invalidation, cleansing your app of stale data with the force of a raging maelstrom, or a dank meme going viral.\n- **Fine-Grained Cache Clearing**: Clear the cache with surgical precision, slicing through cache keys like a skilled samurai, or like a dank meme slicing through the internet.\n- **Seamless Integration**: Harness the power of Django's caching system without breaking a sweat, just like how you effortlessly integrate memes into your conversations.\n- **Extensible Might**: Customize and extend Hydra Cache to fit your twisted caching desires, like a mad scientist tinkering with an unholy creation, or a meme lord crafting the dankest memes.\n\n## Getting Started\n\nAlright, listen up, my fellow memers! Here's how you summon the Kraken of Caching Awesomeness:\n\n1. Install the package like a true caching warrior: `pip install boring-hydra-cache`\n2. In your Django views, import the `HydraCacheMixin` like you're summoning an ancient caching ritual: `from hydra_cache.mixins import HydraCacheMixin`\n3. Create a view class that inherits from both `HydraCacheMixin` and your desired Django view class, binding the Kraken to your unholy will:\n\n```python\nfrom django.views.generic import APIView\nfrom hydra_cache.mixins import HydraCacheMixin\n\nclass MyListView(HydraCacheMixin, APIView):\n    cache_key_prefix = 'my_list_view'\n    cache_timeout = 3600  # 1 hour\n    vary_on_header = 'X-Requested-With'\n\n```\n\n1. In a scenario where you have two separate views - `MyListView` for listing data and `MyCreateUpdateView` for creating or updating data, you can use Hydra Cache to ensure that the cache for `MyListView` is cleared whenever new data is created, updated, or deleted.\n\nFirst, ensure that both views inherit from `HydraCacheMixin`\n\nIn `MyCreateUpdateView`, you would set the `match_on_cache_key` attribute to `True` and list `my_list_view` in the `clear_cache_keys` attribute:\n\n```python\nclass MyCreateUpdateView(HydraCacheMixin, APIView):\n    ...\n    match_on_cache_key = True\n    clear_cache_keys = ['my_list_view']\n    disable_cache = True\n```\n\nWith this setup, any `POST`, `PUT`, `DELETE`, or `PATCH` request made through `MyCreateUpdateView` will automatically clear the cache for `MyListView`, ensuring that the list view always displays the most recent data.\n\nAnd just like that, my friends, you've harnessed the power of Hydra Cache, commanding the multi-headed Kraken of Caching Awesomeness and charting a course towards unparalleled performance and scalability!\n\nBut wait, there's more! With Hydra Cache, you have the power to unleash the Kraken's fury upon your cache whenever you desire, like a true sucker. While the `HydraCacheMixin` automatically handles cache invalidation for `POST`, `PUT`, `DELETE`, and `PATCH` requests, you can also clear the cache independently within your model signals, custom commands, or any other part of your application.\n\nBehold the mighty `flush_cache_for_keys` method, a potent incantation that summons the Kraken's wrath upon specific cache keys:\n\n```python\nfrom hydra_cache.utils import flush_cache_for_keys\n```\n\nFor example, within a Django model signal, you could clear the cache for a specific object:\n\n```python\nfrom django.db.models.signals import post_save\nfrom django.dispatch import receiver\nfrom hydra_cache.utils import flush_cache_for_keys\n\n@receiver(post_save, sender=MyModel)\ndef clear_my_model_cache(sender, instance, **kwargs):\n    cache_key_prefix = f'my_model_{instance.pk}'\n    flush_cache_for_keys(cache_key_prefix)\n\n```\n\n## Conclusion\n\nLook, I get it. Caching can be a real pain in the neck, but with Hydra Cache, you can finally tame the beast and take control of your caching strategies. No more boilerplate code, no more scattered configurations, and no more stale data nightmares. Just pure, unadulterated caching awesomeness!\n\nSo what are you waiting for? Embrace the Kraken, and let the tides of caching ever be in your favor, my fellow meme lords!\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A mixin that unleash the Kraken of DJANGO Caching Power",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/iamharshdev/hydra_cache"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e434f11086ad24d98df39b8df8bebaa8777309f635d9b28295beb88e75309c01",
                "md5": "8f64c834f8ecbf32987071cb001bd5da",
                "sha256": "d270d8e280a5358a6aea7fd0e7327779d429ccc07de9bc1204390122206c0924"
            },
            "downloads": -1,
            "filename": "hydra_cache-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8f64c834f8ecbf32987071cb001bd5da",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6425,
            "upload_time": "2024-05-25T06:56:25",
            "upload_time_iso_8601": "2024-05-25T06:56:25.949195Z",
            "url": "https://files.pythonhosted.org/packages/e4/34/f11086ad24d98df39b8df8bebaa8777309f635d9b28295beb88e75309c01/hydra_cache-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "90c6ab7daf8305a122866595cd41d32e736964e3e38303bd8f3136cd829326e7",
                "md5": "5034f2523e80c2194b2d3700849613fd",
                "sha256": "699e215f742bc0a70189037e64e1fb7c5615bbc2e0b7297407ccfecde56f8f00"
            },
            "downloads": -1,
            "filename": "hydra_cache-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "5034f2523e80c2194b2d3700849613fd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 6069,
            "upload_time": "2024-05-25T06:56:29",
            "upload_time_iso_8601": "2024-05-25T06:56:29.030504Z",
            "url": "https://files.pythonhosted.org/packages/90/c6/ab7daf8305a122866595cd41d32e736964e3e38303bd8f3136cd829326e7/hydra_cache-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-25 06:56:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "iamharshdev",
    "github_project": "hydra_cache",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "asgiref",
            "specs": [
                [
                    "==",
                    "3.8.1"
                ]
            ]
        },
        {
            "name": "Django",
            "specs": [
                [
                    "==",
                    "5.0.6"
                ]
            ]
        },
        {
            "name": "sqlparse",
            "specs": [
                [
                    "==",
                    "0.5.0"
                ]
            ]
        }
    ],
    "lcname": "hydra-cache"
}
        
Elapsed time: 4.84908s