input: Write a function to optimize a Flask application for efficient performance by implementing the following techniques: using Redis for caching session and query performance, using uWSGI for Python applications, using gunicorn as WSGI server, using Flask-Compress extension for compression, using global variables where applicable, avoiding direct SQL queries and always using model methods, using query parameters in URLs instead of plain parameters, and using thread-local objects for performance.
  assert optimize_flask_app('api/<endpoint>', methods=['GET', 'POST']) == "Your code here"
  assert optimize_flask_app('api/<endpoint>', methods=['GET', 'POST']) == "Your code here"
  assert optimize_flask_app('api/<endpoint>', methods=['GET', 'POST']) == "Your code here"
  assert optimize_flask_app('api/<endpoint>', methods=['GET', 'POST']) == "Your code here"
  assert optimize_flask_app('api/<endpoint>', methods=['GET', 'POST']) == "Your code here"
output: def optimize_flask_app(endpoint, methods):
      from flask import Flask, g, request
      from flask_compress import Compress
      import redis
      import threading
  
      app = Flask(__name__)
      Compress(app)
  
      redis_client = redis.StrictRedis(host='localhost', port=6379, db=0)
      thread_local = threading.local()
  
      @app.before_request
      def before_request():
          g.redis = redis_client
          thread_local.endpoint = request.endpoint
  
      @app.route(endpoint, methods=methods)
      def handle_request():
          if g.redis.get(thread_local.endpoint):
              return g.redis.get(thread_local.endpoint)
          
          # Example of using model methods instead of direct SQL queries
          result = model_method_example()
          
          g.redis.set(thread_local.endpoint, result)
          return result
  
      return "Your code here"