mirror of
https://github.com/clearml/clearml-server
synced 2025-01-31 10:56:48 +00:00
21 lines
458 B
Python
21 lines
458 B
Python
|
import functools
|
||
|
|
||
|
|
||
|
class Factory:
|
||
|
default_cls = None
|
||
|
registered_cls = None
|
||
|
|
||
|
@classmethod
|
||
|
@functools.lru_cache(maxsize=None)
|
||
|
def get(cls, *args, **kwargs):
|
||
|
return cls.get_class()(*args, **kwargs)
|
||
|
|
||
|
@classmethod
|
||
|
@functools.lru_cache(maxsize=None)
|
||
|
def get_class(cls):
|
||
|
return cls.registered_cls or cls.default_cls
|
||
|
|
||
|
@classmethod
|
||
|
def register(cls, registered_cls):
|
||
|
cls.registered_cls = registered_cls
|