# Path: cachy/contracts/store.py
# class Store(object):
#     """
#     Abstract class representing a cache store.
#     """
# 
#     _serializer = PickleSerializer()
# 
#     def get(self, key):
#         """
#         Retrieve an item from the cache by key.
# 
#         :param key: The cache key
#         :type key: str
# 
#         :return: The cache value
#         """
#         raise NotImplementedError()
# 
#     def put(self, key, value, minutes):
#         """
#         Store an item in the cache for a given number of minutes.
# 
#         :param key: The cache key
#         :type key: str
# 
#         :param value: The cache value
#         :type value: mixed
# 
#         :param minutes: The lifetime in minutes of the cached value
#         :type minutes: int
#         """
#         raise NotImplementedError()
# 
#     def increment(self, key, value=1):
#         """
#         Increment the value of an item in the cache.
# 
#         :param key: The cache key
#         :type key: str
# 
#         :param value: The increment value
#         :type value: int
# 
#         :rtype: int or bool
#         """
#         raise NotImplementedError()
# 
#     def decrement(self, key, value=1):
#         """
#         Decrement the value of an item in the cache.
# 
#         :param key: The cache key
#         :type key: str
# 
#         :param value: The decrement value
#         :type value: int
# 
#         :rtype: int or bool
#         """
#         raise NotImplementedError()
# 
#     def forever(self, key, value):
#         """
#         Store an item in the cache indefinitely.
# 
#         :param key: The cache key
#         :type key: str
# 
#         :param value: The value
#         :type value: mixed
#         """
#         raise NotImplementedError()
# 
#     def forget(self, key):
#         """
#         Remove an item from the cache.
# 
#         :param key: The cache key
#         :type key: str
# 
#         :rtype: bool
#         """
#         raise NotImplementedError()
# 
#     def flush(self):
#         """
#         Remove all items from the cache.
#         """
#         raise NotImplementedError()
# 
#     def get_prefix(self):
#         """
#         Get the cache key prefix.
# 
#         :rtype: str
#         """
#         raise NotImplementedError()
# 
#     def set_serializer(self, serializer):
#         """
#         Set the serializer.
# 
#         :param serializer: The serializer
#         :type serializer: cachy.serializers.Serializer
# 
#         :rtype: Store
#         """
#         self._serializer = serializer
# 
#         return self
# 
#     def unserialize(self, data):
#         return self._serializer.unserialize(data)
# 
#     def serialize(self, data):
#         return self._serializer.serialize(data)
# 
# Path: cachy/utils.py
# def mkdir_p(path, mode=0o777):
#     try:
#         os.makedirs(path, mode)
#     except OSError as exc:
#         if exc.errno == errno.EEXIST and os.path.isdir(path):
#             pass
#         else:
#             raise
# 
# def encode(string, encodings=None):
#     if isinstance(string, bytes) or PY2 and isinstance(string, unicode):
#         return string
# 
#     if encodings is None:
#         encodings = ['utf-8', 'latin1', 'ascii']
# 
#     for encoding in encodings:
#         try:
#             return string.encode(encoding)
#         except UnicodeDecodeError:
#             pass
# 
#     return string.encode(encodings[0], errors='ignore')


import os
import time
import math
import hashlib
from ..contracts.store import Store
from ..utils import mkdir_p, encode

        if os.path.exists(path):
            os.remove(path)

            return True

        return False

    def flush(self):
        """
        Remove all items from the cache.
        """
        if os.path.isdir(self._directory):
            for root, dirs, files in os.walk(self._directory, topdown=False):
                for name in files:
                    os.remove(os.path.join(root, name))

                for name in dirs:
                    os.rmdir(os.path.join(root, name))

    def _path(self, key):
        """
        Get the full path for the given cache key.

        :param key: The cache key
        :type key: str

        :rtype: str
        """
        hash_type, parts_count = self._HASHES[self._hash_type]

# Path: cachy/contracts/store.py
# class Store(object):
#     """
#     Abstract class representing a cache store.
#     """
# 
#     _serializer = PickleSerializer()
# 
#     def get(self, key):
#         """
#         Retrieve an item from the cache by key.
# 
#         :param key: The cache key
#         :type key: str
# 
#         :return: The cache value
#         """
#         raise NotImplementedError()
# 
#     def put(self, key, value, minutes):
#         """
#         Store an item in the cache for a given number of minutes.
# 
#         :param key: The cache key
#         :type key: str
# 
#         :param value: The cache value
#         :type value: mixed
# 
#         :param minutes: The lifetime in minutes of the cached value
#         :type minutes: int
#         """
#         raise NotImplementedError()
# 
#     def increment(self, key, value=1):
#         """
#         Increment the value of an item in the cache.
# 
#         :param key: The cache key
#         :type key: str
# 
#         :param value: The increment value
#         :type value: int
# 
#         :rtype: int or bool
#         """
#         raise NotImplementedError()
# 
#     def decrement(self, key, value=1):
#         """
#         Decrement the value of an item in the cache.
# 
#         :param key: The cache key
#         :type key: str
# 
#         :param value: The decrement value
#         :type value: int
# 
#         :rtype: int or bool
#         """
#         raise NotImplementedError()
# 
#     def forever(self, key, value):
#         """
#         Store an item in the cache indefinitely.
# 
#         :param key: The cache key
#         :type key: str
# 
#         :param value: The value
#         :type value: mixed
#         """
#         raise NotImplementedError()
# 
#     def forget(self, key):
#         """
#         Remove an item from the cache.
# 
#         :param key: The cache key
#         :type key: str
# 
#         :rtype: bool
#         """
#         raise NotImplementedError()
# 
#     def flush(self):
#         """
#         Remove all items from the cache.
#         """
#         raise NotImplementedError()
# 
#     def get_prefix(self):
#         """
#         Get the cache key prefix.
# 
#         :rtype: str
#         """
#         raise NotImplementedError()
# 
#     def set_serializer(self, serializer):
#         """
#         Set the serializer.
# 
#         :param serializer: The serializer
#         :type serializer: cachy.serializers.Serializer
# 
#         :rtype: Store
#         """
#         self._serializer = serializer
# 
#         return self
# 
#     def unserialize(self, data):
#         return self._serializer.unserialize(data)
# 
#     def serialize(self, data):
#         return self._serializer.serialize(data)
# 
# Path: cachy/utils.py
# def mkdir_p(path, mode=0o777):
#     try:
#         os.makedirs(path, mode)
#     except OSError as exc:
#         if exc.errno == errno.EEXIST and os.path.isdir(path):
#             pass
#         else:
#             raise
# 
# def encode(string, encodings=None):
#     if isinstance(string, bytes) or PY2 and isinstance(string, unicode):
#         return string
# 
#     if encodings is None:
#         encodings = ['utf-8', 'latin1', 'ascii']
# 
#     for encoding in encodings:
#         try:
#             return string.encode(encoding)
#         except UnicodeDecodeError:
#             pass
# 
#     return string.encode(encodings[0], errors='ignore')


# Path: cachy/stores/file_store.py
import os
import time
import math
import hashlib
from ..contracts.store import Store
from ..utils import mkdir_p, encode


        if os.path.exists(path):
            os.remove(path)

            return True

        return False

    def flush(self):
        """
        Remove all items from the cache.
        """
        if os.path.isdir(self._directory):
            for root, dirs, files in os.walk(self._directory, topdown=False):
                for name in files:
                    os.remove(os.path.join(root, name))

                for name in dirs:
                    os.rmdir(os.path.join(root, name))

    def _path(self, key):
        """
        Get the full path for the given cache key.

        :param key: The cache key
        :type key: str

        :rtype: str
        """
        hash_type, parts_count = self._HASHES[self._hash_type]

        h = hash_type(encode(key)).hexdigest()