Index: power_menu.module
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- power_menu.module	(revision b61dd8d4af8e19cc43479ac5557f61fd2e33351b)
+++ power_menu.module	(revision )
@@ -611,9 +611,20 @@
     $entity = $form_state['values']['power_menu']['fields']['entity'];
     entity_form_submit_build_entity('power_menu_fields', $entity, $form['power_menu']['fields'], $form_state);
     $entity->save();
+
+    // Clear cache for given path or the default entry
+    if (isset($form_state['values']['link_path'])) {
+      cache_clear_all('fields:' . $form_state['values']['link_path'], 'cache_power_menu');
-  }
+    }
+    elseif ($entity->mlid == 0) {
+      cache_clear_all('fields:/', 'cache_power_menu');
-}
+    }
 
+    // Clear block cache
+    cache_clear_all('power_menu:power_menu_field_display', 'cache_block', TRUE);
+  }
+}
+
 /**
  * Helper function to call a function in all registred handler objects.
  *
@@ -724,7 +735,14 @@
     $path = implode('/', arg());
   }
 
-  $cache_key = 'fields:' . $path;
+  // The cache is used to store the resolved menu item path from power menu for given system path.
+  // With this mechanism it is not necessary to store the field entity for every system path
+  $cache_path_key = 'path:' . $path;
+  $cached_path = cache_get($cache_path_key, 'cache_power_menu');
+  $lookup_path = $cached_path ? $cached_path->data : $path;
+
+  // Loaded menu field entities also stored in cache. Get it.
+  $cache_key = 'fields:' . $lookup_path;
   $entity = cache_get($cache_key, 'cache_power_menu');
   $entity = $entity ? $entity->data : NULL;
 
@@ -732,27 +750,28 @@
   if (!$entity) {
 
     // Lookup for the default menu field entity?
-    if ($path == '/' && $fallback) {
+    if ($lookup_path == '/' && $fallback) {
 
       $id = power_menu_get_fields_entity_id_by_menu($menu_name);
     }
     else {
       // Is the defined path the front page, get <front> as search condition
-      if (variable_get('site_frontpage', 'node') == $path) {
-        $path = '<front>';
+      if (variable_get('site_frontpage', 'node') == $lookup_path) {
+        $lookup_path = '<front>';
       }
 
       // Get the menu link from given path
       $query = db_select('power_menu_fields', 'pmf');
       $query->leftJoin('menu_links', 'ml', 'pmf.mlid = ml.mlid');
       $id = $query->fields('pmf', array('id'))
-        ->condition('ml.link_path', $path)
+        ->condition('ml.link_path', $lookup_path)
         ->execute()->fetchField();
     }
 
     // No element found, lookup for the default entry
-    if (!$id && $fallback && $path != '/') {
+    if (!$id && $fallback && $lookup_path != '/') {
       $entity = power_menu_get_fields_entity('/', TRUE, $menu_name);
+      $lookup_path = '/';
     }
     elseif ($id) {
       $entity = entity_load('power_menu_fields', array($id));
@@ -760,7 +779,8 @@
       $entity = $entity ? array_pop($entity) : NULL;
     }
 
-    cache_set($cache_key, $entity, 'cache_power_menu');
+    cache_set($cache_path_key, $lookup_path, 'cache_power_menu');
+    cache_set('fields:' . $lookup_path, $entity, 'cache_power_menu');
   }
 
   return $entity;
