Skip to content

Commit c696b3a

Browse files
committed
Use LRUCache to store instantiated components instead of a dictionary which could continue to grow forever.
1 parent 25ebf9c commit c696b3a

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

django_unicorn/components.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from bs4 import BeautifulSoup
1616
from bs4.element import Tag
1717
from bs4.formatter import HTMLFormatter
18+
from cachetools.lru import LRUCache
1819

1920
from . import serializer
2021
from .decorators import timed
@@ -26,7 +27,7 @@
2627

2728

2829
# Module cache to reduce initialization costs
29-
constructed_views_cache = {}
30+
constructed_views_cache = LRUCache(maxsize=100)
3031

3132

3233
class UnicornField:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ beautifulsoup4 = "^4.9.1"
1616
orjson = "^3.2.1"
1717
shortuuid = "^1.0.1"
1818
wrapt = "^1.12.1"
19+
cachetools = "^4.1.1"
1920

2021
[tool.poetry.dev-dependencies]
2122
pytest = "^5.4.3"

0 commit comments

Comments
 (0)