File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55from hishel import AsyncBaseStorage , BaseStorage , Controller
66
7+ from githubkit .typing import HishelControllerOptions
8+
79
810class BaseCache (abc .ABC ):
911 @abc .abstractmethod
@@ -42,12 +44,18 @@ def get_async_cache_storage(self) -> AsyncBaseCache:
4244 """
4345 raise NotImplementedError
4446
45- def get_hishel_controller (self ) -> Optional [Controller ]:
47+ def get_hishel_controller_options (self ) -> HishelControllerOptions :
48+ """Get the hishel controller options"""
49+ # set always revalidate by default
50+ # See: https://hishel.com/examples/github/
51+ return HishelControllerOptions (always_revalidate = True )
52+
53+ def get_hishel_controller (self ) -> Controller :
4654 """Get the hishel controller instance
4755
48- Return `None` to use the default controller
56+ Get the controller options from `get_hishel_controller_options` method
4957 """
50- return None
58+ return Controller ( ** self . get_hishel_controller_options ())
5159
5260 @abc .abstractmethod
5361 def get_hishel_storage (self ) -> BaseStorage :
Original file line number Diff line number Diff line change 33from typing import TYPE_CHECKING , Any , NoReturn , Optional
44from typing_extensions import override
55
6- from hishel import AsyncBaseStorage , AsyncRedisStorage , Controller , RedisStorage
6+ from hishel import AsyncBaseStorage , AsyncRedisStorage , RedisStorage
77
88from githubkit .exception import CacheUnsupportedError
9+ from githubkit .typing import HishelControllerOptions
910from githubkit .utils import hishel_key_generator_with_prefix
1011
1112from .base import AsyncBaseCache , BaseCache , BaseCacheStrategy
@@ -82,14 +83,16 @@ def get_async_cache_storage(self) -> NoReturn:
8283 )
8384
8485 @override
85- def get_hishel_controller (self ) -> Optional [Controller ]:
86+ def get_hishel_controller_options (self ) -> HishelControllerOptions :
87+ options = super ().get_hishel_controller_options ()
88+
8689 if self .prefix is not None :
87- return Controller (
88- key_generator = partial (
89- hishel_key_generator_with_prefix , prefix = self .prefix
90- )
90+ options ["key_generator" ] = partial (
91+ hishel_key_generator_with_prefix , prefix = self .prefix
9192 )
9293
94+ return options
95+
9396 @override
9497 def get_hishel_storage (self ) -> RedisStorage :
9598 return RedisStorage (client = self .client )
Original file line number Diff line number Diff line change 22from datetime import timedelta
33from typing import (
44 IO ,
5+ TYPE_CHECKING ,
56 Annotated ,
67 Callable ,
78 Literal ,
89 NamedTuple ,
910 Optional ,
11+ TypedDict ,
1012 TypeVar ,
1113 Union ,
1214)
1315from typing_extensions import TypeAlias
1416
17+ import httpcore
1518import httpx
1619from pydantic import Field
1720
1821from .compat import PYDANTIC_V2
1922from .exception import GitHubException
2023from .utils import Unset
2124
25+ if TYPE_CHECKING :
26+ from hishel ._utils import BaseClock
27+
2228T = TypeVar ("T" )
2329H = TypeVar ("H" , bound = Hashable )
2430
@@ -89,3 +95,17 @@ class RetryOption(NamedTuple):
8995
9096
9197RetryDecisionFunc : TypeAlias = Callable [[GitHubException , int ], RetryOption ]
98+
99+
100+ class HishelControllerOptions (TypedDict , total = False ):
101+ """Options for the hishel controller."""
102+
103+ cacheable_methods : Optional [list [str ]]
104+ cacheable_status_codes : Optional [list [int ]]
105+ cache_private : bool
106+ allow_heuristics : bool
107+ clock : Optional ["BaseClock" ]
108+ allow_stale : bool
109+ always_revalidate : bool
110+ force_cache : bool
111+ key_generator : Optional [Callable [[httpcore .Request , Optional [bytes ]], str ]]
You can’t perform that action at this time.
0 commit comments