Files
wehub-resource-sync 6b7e6b44f1
gh-pages / build (push) Waiting to run
Python Publish (pypi) / Upload release to PyPI (push) Waiting to run
Spellcheck / spellcheck (push) Waiting to run
Python Build and Type Check / python-ci (ubuntu-latest, 3.11) (push) Has been cancelled
Python Build and Type Check / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Build and Type Check / python-ci (windows-latest, 3.11) (push) Has been cancelled
Python Build and Type Check / python-ci (windows-latest, 3.13) (push) Has been cancelled
Python Integration Tests / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Integration Tests / python-ci (windows-latest, 3.13) (push) Has been cancelled
Python Notebook Tests / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Notebook Tests / python-ci (windows-latest, 3.13) (push) Has been cancelled
Python Smoke Tests / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Smoke Tests / python-ci (windows-latest, 3.13) (push) Has been cancelled
Python Unit Tests / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Unit Tests / python-ci (windows-latest, 3.13) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:37:31 +08:00

97 lines
2.5 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "fcb917cf",
"metadata": {},
"outputs": [],
"source": [
"# Copyright (c) 2026 Microsoft Corporation.\n",
"# Licensed under the MIT License."
]
},
{
"cell_type": "markdown",
"id": "33461307",
"metadata": {},
"source": [
"## Basic cache example\n",
"\n",
"This example shows how to create a JSON cache with file storage using the GraphRAG cache package's configuration system. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ee33abd6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Value stored in cache for 'my_key':\n",
"{'k1': 'object to cache'}\n",
"\n",
"Value stored in cache for cache_key using data dict:\n",
"{'k2': 'object to cache'}\n"
]
}
],
"source": [
"from graphrag_cache import CacheConfig, CacheType, create_cache, create_cache_key\n",
"from graphrag_storage import StorageConfig, StorageType\n",
"\n",
"\n",
"async def run():\n",
" \"\"\"Demonstrate basic cache usage with graphrag_cache.\"\"\"\n",
" cache = create_cache()\n",
"\n",
" # The above is equivalent to the following:\n",
" cache = create_cache(\n",
" CacheConfig(\n",
" type=CacheType.Json,\n",
" storage=StorageConfig(type=StorageType.File, base_dir=\"cache\"),\n",
" ),\n",
" )\n",
"\n",
" await cache.set(\"my_key\", {\"k1\": \"object to cache\"})\n",
" print(\"Value stored in cache for 'my_key':\")\n",
" print(await cache.get(\"my_key\"))\n",
"\n",
" # create cache key from data dict.\n",
" cache_key = create_cache_key({\"some_arg\": \"some_value\", \"something_else\": 5})\n",
" await cache.set(cache_key, {\"k2\": \"object to cache\"})\n",
" print(\"\\nValue stored in cache for cache_key using data dict:\")\n",
" print(await cache.get(cache_key))\n",
"\n",
"\n",
"if __name__ == \"__main__\":\n",
" await run()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}