code: def for_config(cls, config):
      cachedir = cls.cache_dir_from_config(config)
      if config.getoption("cacheclear") and cachedir.exists():
          rm_rf(cachedir)
          cachedir.mkdir()
      return cls(cachedir, config)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import json
  import os
  from collections import OrderedDict
  import attr
  import py
  import six
  import pytest
  from .compat import _PY2
  from .pathlib import Path
  from .pathlib import resolve_from_str
  from .pathlib import rm_rf
label_desc: Use image node_id 1 for calling the Cache obj's underlying member method code with example usage: obj.for_config(cls, config) and returns: cls