{"id":19525711,"url":"https://github.com/maykinmedia/django-dbcache-fields","last_synced_at":"2025-04-26T10:30:48.832Z","repository":{"id":57419688,"uuid":"108149149","full_name":"maykinmedia/django-dbcache-fields","owner":"maykinmedia","description":"This library provides a decorator dbcache that caches the result of your Django Model methods in your database.","archived":false,"fork":false,"pushed_at":"2022-07-15T18:40:54.000Z","size":145,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-20T11:12:49.926Z","etag":null,"topics":["cache","caching","database","decorators","django"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maykinmedia.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-24T15:47:19.000Z","updated_at":"2020-09-28T13:53:55.000Z","dependencies_parsed_at":"2022-09-13T15:32:22.105Z","dependency_job_id":null,"html_url":"https://github.com/maykinmedia/django-dbcache-fields","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maykinmedia%2Fdjango-dbcache-fields","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maykinmedia%2Fdjango-dbcache-fields/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maykinmedia%2Fdjango-dbcache-fields/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maykinmedia%2Fdjango-dbcache-fields/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maykinmedia","download_url":"https://codeload.github.com/maykinmedia/django-dbcache-fields/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250972539,"owners_count":21516378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","caching","database","decorators","django"],"created_at":"2024-11-11T01:06:44.928Z","updated_at":"2025-04-26T10:30:48.470Z","avatar_url":"https://github.com/maykinmedia.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"=====================\nDjango DBCache Fields\n=====================\n\n:Version: 0.9.3\n:Docs: https://django-dbcache-fields.readthedocs.io/\n:Download: https://pypi.python.org/pypi/django_dbcache_fields\n:Source: https://github.com/maykinmedia/django-dbcache-fields\n:Keywords: django, database, cache, methods, decorator\n\n|build-status| |coverage| |license| |pyversion| |djversion|\n\nAbout\n=====\n\nThis library provides a decorator ``dbcache`` that caches the result of your\nDjango ``Model`` methods in your database.\n\nIt adds a regular ``Field`` on your ``Model`` for each method that you\ndecorate. This means you can use all ORM-functions like aggregation and\nmigrations. You can use existing fields or let ``dbcache`` create the field\nfor you.\n\nYou can also invalidate the cached value by creating a _dirty_ function or by\nindicating which other models affect the this cached value. By default, the\ncached value is only updated when the model is saved.\n\nInstallation\n============\n\nYou can install `django_dbcache_fields` either via the Python Package Index\n(PyPI) or from source.\n\nTo install using `pip`:\n\n.. code-block:: console\n\n    $ pip install -U django_dbcache_fields\n\nUsage\n=====\n\nTo use this with your project you need to follow these steps:\n\n#. Install the django_dbcache_fields library:\n\n   .. code-block:: console\n\n      $ pip install django_dbcache_fields\n\n#. Add ``django_dbcache_fields`` to ``INSTALLED_APPS`` in your Django\n   project's ``settings.py``:\n\n   .. code-block:: python\n\n    INSTALLED_APPS = (\n        # ...,\n        'django_dbcache_fields',\n    )\n\n   Note that there is no dash in the module name, only underscores.\n\n#. All done. You can now decorate methods in your ``Model`` with\n   ``@dbcache``.\n\nExample\n=======\n\nSimple example to show what ``dbcache`` does:\n\n.. code-block:: python\n\n    from django.db import models\n    from django_dbcache_fields.decorators import dbcache\n\n    class Ingredient(models.Model):\n        name = models.CharField(max_length=100)\n        price = models.DecimalField(max_digits=4, decimal_places=2)\n\n    class Pizza(models.Model):\n        name = models.CharField(max_length=100)\n        ingredients = models.ManyToManyField(Ingredient)\n\n        @dbcache(models.DecimalField(max_digits=6, decimal_places=2,\n                 blank=True, null=True), invalidated_by=['myapp.Ingredient'])\n        def get_price(self):\n            return self.ingredients.aggregate(total=Sum('price'))['total'] or Decimal()\n\nEvery call to ``get_price`` would normally perform a database query to\ncalculate the total price of all ingredients. However, the ``dbcache``\ndecorator caused a new field to be added to the model: A ``DecimalField`` that\ncan store the resulting value of the ``get_price`` function, so it doesn't\nneed to perform the same query over and over again.\n\n\n.. |build-status| image:: https://secure.travis-ci.org/maykinmedia/django-dbcache-fields.svg?branch=master\n    :alt: Build status\n    :target: https://travis-ci.org/maykinmedia/django-dbcache-fields\n\n.. |coverage| image:: https://codecov.io/github/maykinmedia/django-dbcache-fields/coverage.svg?branch=master\n    :target: https://codecov.io/github/maykinmedia/django-dbcache-fields?branch=master\n\n.. |license| image:: https://img.shields.io/pypi/l/django-dbcache-fields.svg\n    :alt: BSD License\n    :target: https://opensource.org/licenses/BSD-3-Clause\n\n.. |pyversion| image:: https://img.shields.io/pypi/pyversions/django-dbcache-fields.svg\n    :alt: Supported Python versions\n    :target: http://pypi.python.org/pypi/django-dbcache-fields/\n\n.. |djversion| image:: https://img.shields.io/badge/django-1.8%2C%201.9%2C%201.10%2C%201.11%2C%202.0-blue.svg\n    :alt: Supported Django versions\n    :target: http://pypi.python.org/pypi/django-dbcache-fields/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaykinmedia%2Fdjango-dbcache-fields","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaykinmedia%2Fdjango-dbcache-fields","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaykinmedia%2Fdjango-dbcache-fields/lists"}