bbangert / beaker

WSGI middleware for sessions and caching
https://beaker.readthedocs.org/
Other
524 stars 143 forks source link

MongoNamespaceManager using forward slash in namespace for windows environment #178

Open ricksore opened 5 years ago

ricksore commented 5 years ago

I'm currently using a pyramid + mongodb + beaker stack in a project. Tried using cache_region and region_invalidate but the namespace being supplied to the MongoDB write is written in forward slash (native windows directory listing). My hack was to replace the forward slashes in the namespace to backward slashes.

    def _clear_expired(self):
        now = time.time()
        self.namespace = self.namespace.replace('\\', '/')
        self.db.backer_cache.delete_many({'_id': {'$regex': '^%s' % self.namespace},
                                          'expiration': {'$ne': None, '$lte': now}})
amol- commented 5 years ago

Not sure I got why this should only happen in _clear_expired. I get that cache_region is going to generate a namespace based on the file names on disk, which is something you might not want, but the namespace is persisted in the decorated function as _arg_namespace so it should be consistent between cache_region and region_invalidate and always have the same kind of slashes