input: Write a function to optimize a Flask application for efficient performance. The function should implement measures such as using Redis for caching, employing uWSGI and gunicorn as WSGI servers, utilizing Flask-Compress extension for compression, using global variables where applicable, avoiding direct SQL queries and using model methods, and using query parameters in URLs instead of plain parameters. Additionally, it should use thread-local objects for performance enhancements.
  
  assert optimize_flask_app()==expected_output
  assert optimize_flask_app()==expected_output
  assert optimize_flask_app()==expected_output
  assert optimize_flask_app()==expected_output
  assert optimize_flask_app()==expected_output
output: def optimize_flask_app():
      import redis
      from flask import Flask, g
      from flask_compress import Compress
      from werkzeug.local import LocalProxy
  
      app = Flask(__name__)
      Compress(app)
  
      redis_client = redis.StrictRedis(host='localhost', port=6379, db=0)
  
      def get_redis():
          if not hasattr(g, 'redis'):
              g.redis = redis_client
          return g.redis
  
      redis_store = LocalProxy(get_redis)
  
      @app.route('/')
      def index():
          cached_data = redis_store.get('cached_data')
          if cached_data:
              return cached_data.decode('utf-8')
          data = "Hello, World!"
          redis_store.set('cached_data', data)
          return data
  
      return app