invcache-fix4
This commit is contained in:
parent
c1c095a73c
commit
83ec475cc8
21
cache/cache.py
vendored
21
cache/cache.py
vendored
|
@ -7,7 +7,6 @@ from sqlalchemy import and_, join, select
|
||||||
from orm.author import Author, AuthorFollower
|
from orm.author import Author, AuthorFollower
|
||||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||||
from orm.topic import Topic, TopicFollower
|
from orm.topic import Topic, TopicFollower
|
||||||
from resolvers.editor import cache_by_id
|
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
from services.redis import redis
|
from services.redis import redis
|
||||||
from utils.encoders import CustomJSONEncoder
|
from utils.encoders import CustomJSONEncoder
|
||||||
|
@ -348,25 +347,11 @@ async def invalidate_shouts_cache(cache_keys: List[str]):
|
||||||
Инвалидирует кэш выборок публикаций по переданным ключам.
|
Инвалидирует кэш выборок публикаций по переданным ключам.
|
||||||
"""
|
"""
|
||||||
for key in cache_keys:
|
for key in cache_keys:
|
||||||
cache_key = f"shouts:{key}"
|
|
||||||
try:
|
try:
|
||||||
await redis_operation('DEL', cache_key)
|
await redis_operation('DEL', key)
|
||||||
logger.debug(f"Invalidated cache key: {cache_key}")
|
await redis_operation('SETEX', f"{key}:invalidated", value="1", ttl=CACHE_TTL)
|
||||||
|
|
||||||
await redis_operation('SETEX', f"{cache_key}:invalidated", value="1", ttl=CACHE_TTL)
|
|
||||||
|
|
||||||
if key.startswith("topic_"):
|
|
||||||
topic_id = key.split("_")[1]
|
|
||||||
related_keys = [
|
|
||||||
CACHE_KEYS['TOPIC_ID'].format(topic_id),
|
|
||||||
CACHE_KEYS['TOPIC_AUTHORS'].format(topic_id),
|
|
||||||
CACHE_KEYS['TOPIC_FOLLOWERS'].format(topic_id)
|
|
||||||
]
|
|
||||||
for related_key in related_keys:
|
|
||||||
await redis_operation('DEL', related_key)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error invalidating cache key {cache_key}: {e}")
|
logger.error(f"Error invalidating cache key {key}: {e}")
|
||||||
|
|
||||||
|
|
||||||
async def cache_topic_shouts(topic_id: int, shouts: List[dict]):
|
async def cache_topic_shouts(topic_id: int, shouts: List[dict]):
|
||||||
|
|
2
cache/revalidator.py
vendored
2
cache/revalidator.py
vendored
|
@ -1,6 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from cache.cache import cache_author, cache_topic, get_cached_author, get_cached_topic
|
from cache.cache import cache_author, cache_topic, get_cached_author, get_cached_topic, get_cached_entity
|
||||||
from resolvers.stat import get_with_stat
|
from resolvers.stat import get_with_stat
|
||||||
from utils.logger import root_logger as logger
|
from utils.logger import root_logger as logger
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user