Storing data in memcache
The memcache is an in-memory, key-value database store, just like Redis. After you install and run the memcached server, install the memcache Python client using the following command:
$ pip3 install python3-memcache
The code in the ch-08.ipynb
file creates a memcache client and then stores the DataFrame to memcache with an auto-expire value of 600
seconds. The code is similar to the code for Redis:
import memcache import statsmodels.api as sm import pandas as pd client = memcache.Client([('127.0.0.1', 11211)]) data_loader = sm.datasets.sunspots.load_pandas() df = data_loader.data data = df.T.to_json() client.set('sunspots', data, time=600) print("Stored data to memcached, auto-expire after 600 seconds") blob = client.get('sunspots') print(pd.read_json(blob))