Files
swift/swift/common/middleware/memcache.py
Matthew Oliver a8516e1510 Refactor memcache config and MemcacheRing loading
The loading and creation of the Memcache ring in the middleware is
rather interesting. It not only reads the config file, but also may
look for a `/etc/swift/memcache.conf`. Further, we are know are
looking at using the MemcacheRing client in more places.

So this patch moves the config reading from the middleware and
into a `load_memcache` helper method in swift/common/memcached.py.

Drive-by: cleanup unused stuff in middleware test module

Change-Id: I028722facfbe3ff8092b6bdcc931887a169cc49a
2022-10-26 11:01:18 +01:00

43 lines
1.3 KiB
Python

# Copyright (c) 2010-2012 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from swift.common.memcached import load_memcache
from swift.common.utils import get_logger
class MemcacheMiddleware(object):
"""
Caching middleware that manages caching in swift.
"""
def __init__(self, app, conf):
self.app = app
self.logger = get_logger(conf, log_route='memcache')
self.memcache = load_memcache(conf, self.logger)
def __call__(self, env, start_response):
env['swift.cache'] = self.memcache
return self.app(env, start_response)
def filter_factory(global_conf, **local_conf):
conf = global_conf.copy()
conf.update(local_conf)
def cache_filter(app):
return MemcacheMiddleware(app, conf)
return cache_filter