blob: b4b18c23f325df9052d6d0afbf52888dbbe9e7bf [file] [log] [blame]
{"version":3,"sources":["webpack:///./src/pages/docs/installation/caching.mdx"],"names":["_frontmatter","layoutProps","MDXLayout","DefaultLayout","MDXContent","components","props","mdxType","parentName","isMDXComponent"],"mappings":"wPAQaA,G,UAAe,S,yNAC5B,IAAMC,EAAc,CAClBD,gBAEIE,EAAYC,IACH,SAASC,EAAT,GAGZ,IAFDC,EAEC,EAFDA,WACGC,EACF,8BACD,OAAO,YAACJ,EAAD,eAAeD,EAAiBK,EAAhC,CAAuCD,WAAYA,EAAYE,QAAQ,cAG5E,iBAAQ,CACN,GAAM,WADR,WAGA,sCAAqB,6BAAGC,WAAW,KAAQ,CACvC,KAAQ,0CADS,eAArB,qFAG6C,0BAAYA,WAAW,KAAvB,gBAH7C,sBAG4H,0BAAYA,WAAW,KAAvB,sBAH5H,wDAKA,8IAEA,sBACE,kBAAIA,WAAW,MAAf,iCAAsD,6BAAGA,WAAW,MAAS,CACzE,KAAQ,sCAD0C,WAAtD,uBAGJ,0BAAYA,WAAW,MAAvB,oBAHI,mDAIA,kBAAIA,WAAW,MAAf,2BAAgD,6BAAGA,WAAW,MAAS,CACnE,KAAQ,uCADoC,SAAhD,oBAIF,4EACA,sRAE4D,0BAAYA,WAAW,KAAvB,gBAF5D,KAGA,uBAAK,gCAAMA,WAAW,OAAU,IAA3B,6NAOL,sEAAqD,6BAAGA,WAAW,KAAQ,CACvE,KAAQ,0EADyC,QAArD,mBAGA,gKACkC,0BAAYA,WAAW,KAAvB,uBADlC,eACiH,0BAAYA,WAAW,KAAvB,aADjH,KAEA,uBAAK,gCAAMA,WAAW,OAAU,CAC5B,UAAa,oBADZ,oTAcL,yIACoB,0BAAYA,WAAW,KAAvB,2BADpB,UAEA,iBAAQ,CACN,GAAM,sBADR,sBAGA,qHACA,uBAAK,gCAAMA,WAAW,OAAU,IAA3B,4FAKL,8KAEA,kFACA,uBAAK,gCAAMA,WAAW,OAAU,CAC5B,UAAa,oBADZ,0oBAyBL,kFAAiE,0BAAYA,WAAW,KAAvB,mCAAjE,wDAEA,uBAAK,gCAAMA,WAAW,OAAU,IAA3B,yDAEL,qFAAoE,0BAAYA,WAAW,KAAvB,2BAApE,kGACkF,0BAAYA,WAAW,KAAvB,eADlF,uEAGA,uBAAK,gCAAMA,WAAW,OAAU,CAC5B,UAAa,oBADZ,+EAKL,+CACA,uBAAK,gCAAMA,WAAW,OAAU,IAA3B,8C,uNAMTJ,EAAWK,gBAAiB","file":"component---src-pages-docs-installation-caching-mdx-8a5cd3f2aab4c43b5457.js","sourcesContent":["import * as React from 'react'\n /* @jsx mdx */\nimport { mdx } from '@mdx-js/react';\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\n\nimport DefaultLayout from \"/Users/max/code/superset2/docs/node_modules/gatsby-theme-docz/src/base/Layout.js\";\nexport const _frontmatter = {};\nconst layoutProps = {\n _frontmatter\n};\nconst MDXLayout = DefaultLayout;\nexport default function MDXContent({\n components,\n ...props\n}) {\n return <MDXLayout {...layoutProps} {...props} components={components} mdxType=\"MDXLayout\">\n\n\n <h2 {...{\n \"id\": \"caching\"\n }}>{`Caching`}</h2>\n <p>{`Superset uses `}<a parentName=\"p\" {...{\n \"href\": \"https://pythonhosted.org/Flask-Cache/\"\n }}>{`Flask-Cache`}</a>{` for caching purpose. Configuring\nyour caching backend is as easy as providing a `}<inlineCode parentName=\"p\">{`CACHE_CONFIG`}</inlineCode>{`, constant in your `}<inlineCode parentName=\"p\">{`superset_config.py`}</inlineCode>{`\nthat complies with the Flask-Cache specifications.`}</p>\n <p>{`Flask-Cache supports multiple caching backends (Redis, Memcached, SimpleCache (in-memory), or the\nlocal filesystem).`}</p>\n <ul>\n <li parentName=\"ul\">{`Memcached: we recommend using `}<a parentName=\"li\" {...{\n \"href\": \"https://pypi.org/project/pylibmc/\"\n }}>{`pylibmc`}</a>{` client library as\n`}<inlineCode parentName=\"li\">{`python-memcached`}</inlineCode>{` does not handle storing binary data correctly.`}</li>\n <li parentName=\"ul\">{`Redis: we recommend the `}<a parentName=\"li\" {...{\n \"href\": \"https://pypi.python.org/pypi/redis\"\n }}>{`redis`}</a>{` Python package`}</li>\n </ul>\n <p>{`Both of these libraries can be installed using pip.`}</p>\n <p>{`For setting your timeouts, this is done in the Superset metadata and goes up the “timeout\nsearchpath”, from your slice configuration, to your data source’s configuration, to your database’s\nand ultimately falls back into your global default defined in `}<inlineCode parentName=\"p\">{`CACHE_CONFIG`}</inlineCode>{`.`}</p>\n <pre><code parentName=\"pre\" {...{}}>{`CACHE_CONFIG = {\n 'CACHE_TYPE': 'redis',\n 'CACHE_DEFAULT_TIMEOUT': 60 * 60 * 24, # 1 day default (in secs)\n 'CACHE_KEY_PREFIX': 'superset_results',\n 'CACHE_REDIS_URL': 'redis://localhost:6379/0',\n}\n`}</code></pre>\n <p>{`Custom cache backends are also supported. See `}<a parentName=\"p\" {...{\n \"href\": \"https://flask-caching.readthedocs.io/en/latest/#custom-cache-backends\"\n }}>{`here`}</a>{` for specifics.`}</p>\n <p>{`Superset has a Celery task that will periodically warm up the cache based on different strategies.\nTo use it, add the following to the `}<inlineCode parentName=\"p\">{`CELERYBEAT_SCHEDULE`}</inlineCode>{` section in `}<inlineCode parentName=\"p\">{`config.py`}</inlineCode>{`:`}</p>\n <pre><code parentName=\"pre\" {...{\n \"className\": \"language-python\"\n }}>{`CELERYBEAT_SCHEDULE = {\n 'cache-warmup-hourly': {\n 'task': 'cache-warmup',\n 'schedule': crontab(minute=0, hour='*'), # hourly\n 'kwargs': {\n 'strategy_name': 'top_n_dashboards',\n 'top_n': 5,\n 'since': '7 days ago',\n },\n },\n}\n`}</code></pre>\n <p>{`This will cache all the charts in the top 5 most popular dashboards every hour. For other\nstrategies, check the `}<inlineCode parentName=\"p\">{`superset/tasks/cache.py`}</inlineCode>{` file.`}</p>\n <h3 {...{\n \"id\": \"caching-thumbnails\"\n }}>{`Caching Thumbnails`}</h3>\n <p>{`This is an optional feature that can be turned on by activating it’s feature flag on config:`}</p>\n <pre><code parentName=\"pre\" {...{}}>{`FEATURE_FLAGS = {\n \"THUMBNAILS\": True,\n \"THUMBNAILS_SQLA_LISTENERS\": True,\n}\n`}</code></pre>\n <p>{`For this feature you will need a cache system and celery workers. All thumbnails are store on cache\nand are processed asynchronously by the workers.`}</p>\n <p>{`An example config where images are stored on S3 could be:`}</p>\n <pre><code parentName=\"pre\" {...{\n \"className\": \"language-python\"\n }}>{`from flask import Flask\nfrom s3cache.s3cache import S3Cache\n\n...\n\nclass CeleryConfig(object):\n BROKER_URL = \"redis://localhost:6379/0\"\n CELERY_IMPORTS = (\"superset.sql_lab\", \"superset.tasks\", \"superset.tasks.thumbnails\")\n CELERY_RESULT_BACKEND = \"redis://localhost:6379/0\"\n CELERYD_PREFETCH_MULTIPLIER = 10\n CELERY_ACKS_LATE = True\n\n\nCELERY_CONFIG = CeleryConfig\n\ndef init_thumbnail_cache(app: Flask) -> S3Cache:\n return S3Cache(\"bucket_name\", 'thumbs_cache/')\n\n\nTHUMBNAIL_CACHE_CONFIG = init_thumbnail_cache\n# Async selenium thumbnail task will use the following user\nTHUMBNAIL_SELENIUM_USER = \"Admin\"\n`}</code></pre>\n <p>{`Using the above example cache keys for dashboards will be `}<inlineCode parentName=\"p\">{`superset_thumb__dashboard__{ID}`}</inlineCode>{`. You can\noverride the base URL for selenium using:`}</p>\n <pre><code parentName=\"pre\" {...{}}>{`WEBDRIVER_BASEURL = \"https://superset.company.com\"\n`}</code></pre>\n <p>{`Additional selenium web drive configuration can be set using `}<inlineCode parentName=\"p\">{`WEBDRIVER_CONFIGURATION`}</inlineCode>{`. You can\nimplement a custom function to authenticate selenium. The default function uses the `}<inlineCode parentName=\"p\">{`flask-login`}</inlineCode>{`\nsession cookie. Here's an example of a custom function signature:`}</p>\n <pre><code parentName=\"pre\" {...{\n \"className\": \"language-python\"\n }}>{`def auth_driver(driver: WebDriver, user: \"User\") -> WebDriver:\n pass\n`}</code></pre>\n <p>{`Then on configuration:`}</p>\n <pre><code parentName=\"pre\" {...{}}>{`WEBDRIVER_AUTH_FUNC = auth_driver\n`}</code></pre>\n\n </MDXLayout>;\n}\n;\nMDXContent.isMDXComponent = true;\n "],"sourceRoot":""}