Package: dory-cache
DoryDory is aPython3.8+out-of-the box smart cache library. It simplifies multiple cache features and bringsBloatsto the table, a tool designed to make smarter your application cache.BadgesBuildDocsPackageSupportTable of contentInstallationFeaturesCache utilsBloatsUsageExamplesRoadmapContributingInstallationInstallation is as simple as:pipinstalldory-cacheFeaturesCache utilsDorysimplifies several cache utilities with an out-of-the-box interface. For example, a decorator to cache views comfortably:@api.get('/foo')@dory.cache(key='foo',timeout=timedelta(hours=1))deffoo(request):"""Render a Foo"""...More about it on thedocs🔥BloatsPorcupinefish have the ability to inflate their bodies by swallowing water or air, thereby becoming rounder.Bloatsresponds to the necessity to have a solid and clean way to define cache usage and to permit an smart cache approach to your system.
The main idea behind it is that aBloathas the ability toinflate-as a Porcupinefish does- meaning that has the ability to cache akey/valuegiven a certain configuration.
Also, has the ability todeflatemeaning exactly the contrary, that deletes the givenkey/valuefrom the cache. Having aBloatdecoupled gives the application the ability to interact with the cache in a comfortable way around all the project.For example, let's pretend that we have a model calledProductwich can be either renderizer or edited.classProduct(Model):"""Store information about a Product"""id:int=PrimaryKey()name:str=Text()description:str=Text()So, to improve theProductperformance we cache theProductserialization view(GET /product).@api.get('/product/<id>')@dory.cache(key=lambdarequest,id:"product:%s"%id,timeout=timedelta(hours=1))defget_product(request,id)->Response:"""Serialize a Product"""...Now everything works faster and as expected, but we did not contemplate that since theProductcan be edited(POST /product), we could have cached an outdated version of theProduct, so we need a way to force the cache to refresh itself. This is whereBloatscome in handy!Instead of caching the view with a custom key, decouple the cache configuration on aBloat:classProduct(dory.Bloat):"""Product's bloat"""prefix:str='product'key:strtimeout:timedelta=timedelta(hours=1)enabled:bool=Truedef__init__(product_id:int):self.key='%s'%product_id@api.get('/product/<id>')@bloats.Product.cache(args=lambdarequest,id:dict(product_id=id))defget_product(request,id)->Response:"""Serialize a Product"""...And now, when aProductis edited, you can force the view to refresh the cache using theBloatas a middle-man.@api.post('/product/<id>')defedit_product(request,id):"""Edit a Product"""# edit the productservices.product.edit(request.body)# clean up outdated cachebloats.Product(product_id=id).deflate()Now your cache will always be in sync and it'll be configured in a cleaner way! 🔥RoadmapCache utils(SeeCache utils)Cache decoratorRatelimitBloats 🐡(SeeBloats)Django signalsclassProduct(models.Model,dory.django.BloatModel):"""Store information about a Product"""id:intname:str=m.CharField(max_length=24)description:str=m.TextField()@api.get('/product/<id>')@bloats.Product.cache(args=lambdarequest,id:dict(product_id=id),deflate_on=models.Product.post_save)defget_product(request,id):"""Serialize a Product"""...Bloats v2The v2 of theBloatswill implement the method.reflate(), capable not only todeflatethe currentBloatbut toinflateit again. The design is still aWIP.ContributingSuggestions and contributions are extremely welcome! ❤️Just open an issue or a PR, and I'll respond as soon as I can.