playfire / django-cache-toolbox Goto Github PK
View Code? Open in Web Editor NEWNon-magical object caching for Django
Home Page: http://code.playfire.com/django-cache-toolbox
License: BSD 3-Clause "New" or "Revised" License
Non-magical object caching for Django
Home Page: http://code.playfire.com/django-cache-toolbox
License: BSD 3-Clause "New" or "Revised" License
Let's say I have a Person object with a ForeignKey to a default image.
class Person(models.Model):
default_image = models.ForeignKey('people.Image', blank=True, null=True,
on_delete=models.SET_NULL)
class Image(models.Model):
some_image_field = models.ImageField(...)
>>> p = Person.objects.get(first_name='Phil')
>>> img = Image.objects.get(**some_kwargs)
>>> p_cached = Person.get_cached(pk=p.pk)
>>> p.default_image = img
>>> p.save()
>>> p_cached = Person.get_cached(pk=p.pk)
>>> p.default_image is not None
True
>>> p_cached.default_image is not None
True
>>> img.delete()
>>> p.default_image is None
True
>>> p_cached = Person.get_cached(pk=p.pk)
>>> p_cached.default_image is None
Traceback (most recent call last)
...
File "django/db/models/fields/related.py", line 316, in __get__
rel_obj = QuerySet(self.field.rel.to).using(db).get(**params)
DoesNotExist: Image matching query does not exist.
It's a pretty tricky bug, and it may be nearly impossible to fix if the on_delete actually sets a database property that leads to that behavior rather than doing it in Python.
Nonetheless, I felt I should probably report it just so it's a known issue.
Hi there!
Great work on this project. It looks like the commits have been coming fast recently, and I realize you say support for ForeignKey fields is planned, but I just wanted to put a ticket in to ping you about that.
ForeignKey support would be a great feature and would significantly decrease db hits for me.
The scaling isn't that important for me yet, so I probably won't be able to commit any time to helping out with this feature in the immediate future, but once we go live if this is a bottleneck I'd certainly be happy to work on this.
Thanks!
The db origin of an instance isn't set for objects retrieved from the cache, which means they can't usually be used against as ForeignKey/ManyToMany fields.
How about serializing the FileField to the relative file name?
this should at very least be in the documentation if you don't plan on fixing it soon
edited:
actually that doesn't seem right at all, the issue i'm seeing is when the primary key of the related object is out of sync with the parent object
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.