Hello,

I'm having a strange problem with CachingQuery.

I have a model that looks like this:

User(object):
.....
    @classmethod
    def by_id(cls, id, cache=FromCache("default", "by_id"),
invalidate=False):
        q = meta.Session.query(User).filter(User.id == id)
        if cache:
            q = q.options(cache)
        if invalidate:
            q.invalidate()
            return True
        return q.first()

    @classmethod
    def by_username(cls, username, cache=FromCache("default",
"by_username"), invalidate=False):
        q = meta.Session.query(User).filter(User.username == username)
        if cache:
            q = q.options(cache)
        if invalidate:
            q.invalidate()
            return True
        return q.first()
....

now unless i call User.by_id(id, invalidate=True), All my queries
contain wrong cached data.
even if i do directly in controller of my app something like:

c.users = meta.Session.query(User).order_by(User.username).limit(30)
the returned rows will have different values than in database.
What is more funnier, i only invalidate cache if i invalidate with:
User.by_id(id, invalidate=True),
when in some other action i did User.by_username(username,
invalidate=True), i saw the query performed to the database - which
would mean that cache WAS invalidated, but returned data was still old
cached one.
And no its not template caching, ive performed all my tests inside
controller.
What else can be causing query to return wrong data ?

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to