Skip to content

cache

Classes:

Functions:

ClipFramesCache

Bases: NodeFramesCache[VideoNode, VideoFrame]

ClipsCache

Bases: VSObjectABC, UserDict[VideoNode, VideoNode]

DynamicClipsCache

DynamicClipsCache(cache_size: int = 2)

Bases: VSObjectABC, UserDict[T, VideoNode]

Methods:

Attributes:

Source code in vstools/utils/cache.py
34
35
36
def __init__(self, cache_size: int = 2) -> None:
    super().__init__()
    self.cache_size = cache_size

cache_size instance-attribute

cache_size = cache_size

get_clip abstractmethod

get_clip(key: T) -> VideoNode
Source code in vstools/utils/cache.py
38
39
@abstractmethod
def get_clip(self, key: T) -> vs.VideoNode: ...

FramesCache

FramesCache(clip: NodeT, cache_size: int = 10)

Bases: VSObjectABC, UserDict[int, FrameT]

Methods:

Attributes:

Source code in vstools/utils/cache.py
72
73
74
75
def __init__(self, clip: NodeT, cache_size: int = 10) -> None:
    super().__init__()
    self.clip: NodeT = clip
    self.cache_size = cache_size

cache_size instance-attribute

cache_size = cache_size

clip instance-attribute

clip: NodeT = clip

add_frame

add_frame(n: int, f: FrameT) -> FrameT
Source code in vstools/utils/cache.py
77
78
79
80
def add_frame(self, n: int, f: FrameT) -> FrameT:
    f = f.copy()
    self[n] = f
    return f

get_frame

get_frame(n: int, f: FrameT) -> FrameT
Source code in vstools/utils/cache.py
82
83
def get_frame(self, n: int, f: FrameT) -> FrameT:
    return self[n]

LRUCache

LRUCache(cache_size: int = 10)

Bases: VSObject, OrderedDict[K, V]

Attributes:

Source code in vstools/utils/cache.py
52
53
54
def __init__(self, cache_size: int = 10) -> None:
    super().__init__()
    self.cache_size = cache_size

cache_size instance-attribute

cache_size = cache_size

NodeFramesCache

Bases: VSObjectABC, UserDict[NodeT, FramesCache[NodeT, FrameT]]

NodesPropsCache

NodesPropsCache(cache_size: int = 10)

Bases: LRUCache[tuple[NodeT, int], MutableMapping[str, '_PropValue']]

Attributes:

Source code in vstools/utils/cache.py
52
53
54
def __init__(self, cache_size: int = 10) -> None:
    super().__init__()
    self.cache_size = cache_size

cache_size instance-attribute

cache_size = cache_size

cache_clip

cache_clip(_clip: NodeT, cache_size: int = 10) -> NodeT
Source code in vstools/utils/cache.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def cache_clip[NodeT: vs.RawNode](_clip: NodeT, cache_size: int = 10) -> NodeT:
    if isinstance(_clip, vs.VideoNode):
        cache = FramesCache[vs.VideoNode, vs.VideoFrame](_clip, cache_size)

        blank = vs.core.std.BlankClip(_clip)

        to_cache_node = vs.core.std.ModifyFrame(blank, _clip, cache.add_frame)
        from_cache_node = vs.core.std.ModifyFrame(blank, blank, cache.get_frame)

        return vs.core.std.FrameEval(blank, lambda n: from_cache_node if n in cache else to_cache_node)  # type: ignore[return-value]

    # elif isinstance(_clip, vs.AudioNode):
    #     ...

    return _clip