'How to setup memcached for Django 3.0 on App Engine?

So I have a Django 3.0 app that I want to deploy to App Engine. I want to use Memcached in order to cache data that has been pulled from BQ to my Django app. So far what I have is that I set up my Django's views.py as follows:

from google.appengine.api import memcache

def index(request):
     cached_data = memcache.get('cached_data')
     
     if not cached_data:
          # Syntax to pull data here
          memcache.add(key='cached_data', value='pulled_data', time=3600)

My app.yaml also includes

app_engine_apis: true

However, after deploying the app using gcloud app deploy and opening the web app, I'm getting a 500 Server Error. I believe this error is because of the Memcached but I'm not sure what I am missing.

Additional Note: I have not set any CACHES in my settings.py as none were mentioned on the GCP website. I used this during development locally:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache',
        'LOCATION': '127.0.0.1:11211',
    }
}

But then I removed it right before deploying to App Engine.

I've tried following this SO Answer but it didn't work for me.

UPDATE 500 SERVER ERROR Log 500 Server Error

Screenshot of the log 500 Server Error



Solution 1:[1]

I would discourage this option has it involves using the Python2 Google App Engine environment. Python2 is very legacy and currently is no longer supported by the community.

The best option would be to use the Python3 runtime and instead of Memcache use Firestore to store your data. Firestore is a NoSQL document database built for automatic scaling, high performance, and ease of application development.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 llompalles