-
-
Notifications
You must be signed in to change notification settings - Fork 723
Expand file tree
/
Copy pathplugin_cache.py
More file actions
68 lines (56 loc) · 1.7 KB
/
plugin_cache.py
File metadata and controls
68 lines (56 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (c) nexB Inc. and others. All rights reserved.
#
"""
CLI plugin to enable result caching.
"""
import click
from plugincode.scan import ScanPlugin
from plugincode.scan import scan_impl
from scancode.cache_manager import ResultCache
@scan_impl
class CachePlugin(ScanPlugin):
"""
Enable file-level result caching for faster repeated scans.
"""
options = [
click.Option(
['--cache'],
is_flag=True,
default=False,
help='Enable result caching for faster repeated scans.',
),
click.Option(
['--cache-dir'],
type=click.Path(exists=False, file_okay=False, dir_okay=True),
metavar='DIR',
help='Custom directory for cache storage. '
'Default: ~/.cache/scancode/file_results',
),
click.Option(
['--force-reindex'],
is_flag=True,
default=False,
help='Ignore cache and perform full rescan of all files.',
),
]
def is_enabled(self, cache, **kwargs):
return cache
def setup(self, **kwargs):
"""
Initialize cache manager for the scan.
"""
pass
def get_cache_manager(cache, cache_dir, **kwargs):
"""
Factory function to get cache manager instance.
Args:
cache: Boolean, whether caching is enabled
cache_dir: Custom cache directory path
Returns:
ResultCache instance or None if caching disabled
"""
if not cache:
return None
return ResultCache(cache_dir=cache_dir)