diff --git a/download_count.module b/download_count.module
index 9e71ee5..2ff4643 100644
--- a/www/sites/all/modules/download_count/download_count.module
+++ b/www/sites/all/modules/download_count/download_count.module
@@ -133,13 +133,37 @@ function download_count_library() {
 }
 
 /**
+ * Implements hook_file_download_access().
+ */
+function downloadcounter_file_download_access($file_item, $entity_type, $entity){
+   _download_count_cache_entity_download($file_item['fid'], $entity);
+  return FALSE;
+}
+
+function _download_count_cache_entity_download($fid, $entity=NULL) {
+  static $fidcache = 0;
+  static $entitycache = NULL;
+  if (is_null($entity)){
+    if ($fidcache == $fid) {
+      return $entitycache;
+    }
+  }
+  else {
+    $fidcache = $fid;
+    $entitycache = $entity;
+    return NULL;
+  }
+}
+
+/**
  * Implements hook_file_download_access_alter().
  */
-function download_count_file_download_access_alter(&$grants, $file, $entity_type, $entity) {
+function download_count_file_download_access_alter(&$grants, $file, $entity_type, $entity=NULL) {
   $time =  REQUEST_TIME;
+  $entity =  _download_count_cache_entity_download($file_item['fid']);
 
   //if no access, simply return.
-  if (!in_array(TRUE, $grants)) {
+  if (!in_array(TRUE, $grants) || is_null($entity)) {
     return;
   }
 
