Question: I am trying to integrate redis to scalacache. Keys are usually string but values can be objects, Set[String], etc. Cache is initialized by this

```
val cache: RedisCache = RedisCache(config.host, config.port)
private implicit val scalaCache: ScalaCache[Array[Byte]] = ScalaCache(cacheService.cache)

```

But while calling put, i am getting this error "Could not find any Codecs for type Set[String] and Repr". Looks like i need to provide codec for my cache input as suggested [here](https://github.com/cb372/scalacache#custom-codec) so i added,

```
class A extends Codec[Set[String], Array[Byte]] with GZippingBinaryCodec[Set[String]]

```

Even after, my class A, is throwing the same error. What am i missing.

Answer: 
If you look at the [MRO](https://docs.python.org/3/glossary.html#term-method-resolution-order) of the class `Car` you can see:

```
>>> Car.__mro__
(<class '__main__.Car'>, <class '__main__.ReferenceData'>, <type 'object'>)

```

So methods are looked up first on `Car`, then on `ReferenceData` and finally on `object`.

Compare this to the MRO of your new class (I use `NewCar` as name for clarity):

```
>>> type('NewCar', (Car, MockReferenceData), {}).__mro__
(<class '__main__.NewCar'>, <class '__main__.Car'>, <class '__main__.ReferenceData'>, <class '__main__.MockReferenceData'>, <type 'object'>)

```

This contains the MRO of the `Car` class. Methods here are still looked up first on `Car` and then on `ReferenceData`, so as `totalNumberOfSeats` is found on `ReferenceData` the implementation from `MockReferenceData` is not used.

What you could do is to insert your mock class in the MRO *before* the `Car` class:

```
>>> type('NewCar', (MockReferenceData, Car), {}).__mro__
(<class '__main__.NewCar'>, <class '__main__.MockReferenceData'>, <class '__main__.Car'>, <class '__main__.ReferenceData'>, <type 'object'>)

```

Now methods will befirst looked up in the `MockReferenceData` class and if they do not exist there fall back to the previous version. So this `extend_instance` method should work for this simple case:

```
def extend_instance(obj, cls):
    """Apply mixins to a class instance after creation"""
    obj.__class__ = type(obj.__class__.__name__, (cls, obj.__class__),{})

```
Don't use inheritance. It's a overused abstraction in many cases, and this is an example. By using dependency-injection, you can easily default to the actual DB, but replace your backend with a mocked one.

```
class MockReferenceData(object):
  def dbName(self):
    return 'mock'

  def totalNumberOfSeats(self):
    return '10'

class ReferenceData(object):
  def dbName(self):
    return 'real DB'

  def totalNumberOfSeats(self):
    return 'Fetch from DB'

class Car(object):

    def __init__(self, datasource_class=ReferenceData):
        self._datasource = datasource_class() # instead of creation here, you could also pass in an

    def showNumberOfSeats(self):
        print(self._datasource.totalNumberOfSeats())

real_car = Car()
real_car.showNumberOfSeats()

mocked_car = Car(datasource_class=MockReferenceData)
mocked_car.showNumberOfSeats()

```

Also please follow PEP8 for coding-conventions in Python. You use the "wrong" indentation depth of 2, resulting in editing problems for fellow developers like me. Same goes for method-names.