diff --git a/cache.inc b/cache.inc
index 5174176..0306440 100644
--- a/cache.inc
+++ b/cache.inc
@@ -96,7 +96,16 @@ function _cache_get_object($bin) {
  *   The cache or FALSE on failure.
  */
 function cache_get($cid, $bin = 'cache') {
-  return _cache_get_object($bin)->get($cid);
+  $cached = _cache_get_object($bin)->get($cid);
+  // See cache_set().
+  if (FALSE !== $cached) {
+    $data = $cached->data;
+    if ($data instanceof CacheItemWrapper) {
+      $cached->data = $data->data;
+      $cached->headers = $data->headers;
+    }
+  }
+  return $cached;
 }
 
 /**
@@ -183,7 +192,11 @@ function cache_get_multiple(array &$cids, $bin = 'cache') {
  *   - A Unix timestamp: Indicates that the item should be kept at least until
  *     the given time, after which it behaves like CACHE_TEMPORARY.
  */
-function cache_set($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT) {
+function cache_set($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT, $headers = NULL) {
+  if (isset($headers)) {
+    // Work-arround different cache backend signature from D6 to D7.
+    $data = new CacheItemWrapper($data, $headers);
+  }
   return _cache_get_object($bin)->set($cid, $data, $expire);
 }
 
@@ -235,6 +248,26 @@ function cache_is_empty($bin) {
 }
 
 /**
+ * Cache item wrapper, used only if the headers array is present.
+ */
+class CacheItemWrapper {
+  /**
+   * @var mixed
+   */
+  public $data;
+
+  /**
+   * @var string|array
+   */
+  public $headers;
+
+  public function __construct($data, $headers = null) {
+    $this->data = $data;
+    $this->headers = $headers;
+  }
+}
+
+/**
  * Interface for cache implementations.
  *
  * All cache implementations have to implement this interface.
