<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Local storage strategy</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : Community Forum : Local storage strategy</description>
  <pubDate>Fri, 10 Apr 2026 21:40:48 -700</pubDate>
  <lastBuildDate>Mon, 08 Oct 2012 10:03:17 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=3697</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Local storage strategy : Ok, per your your request, to...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3697&amp;PID=14782#14782</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1524" rel="nofollow">jtraband</a><br /><strong>Subject:</strong> 3697<br /><strong>Posted:</strong> 08-Oct-2012 at 10:03am<br /><br /><font face="C&#111;nsolas" size="2"><font face="C&#111;nsolas" size="2">Ok, per your your request, to implement this<br></font></font><br>-make remote query<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -if it fails make local query</div><div>-save to local storage<br><br>Try this, ( I didn't actually test it so ... )<br><br><b>var results;</b><br><br></div><font face="C&#111;nsolas" size="2"><font face="C&#111;nsolas" size="2">myE<strong>ntityManager.executeQuery(query)<br>&nbsp; &nbsp;&nbsp; &nbsp; .then( function(data) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; results = data.results;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; processResultsAndStoreLocally(results);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })<br>&nbsp; &nbsp;&nbsp; &nbsp; .fail( function(e) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // maybe log the error ...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; results = entityManager.executeQueryLocally(query);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; processResultsAndStoreLocally(results);<br>&nbsp; &nbsp;&nbsp; &nbsp; });<br>}<br><br>function processResultsAndStoreLocally(results) {<br>&nbsp;&nbsp; // process your results<br><font face="C&#111;nsolas" size="2"><font face="C&#111;nsolas" size="2"><strong>&nbsp;&nbsp; saveToLocalStorage();</strong></font></font></strong></font></font><br><font face="C&#111;nsolas" size="2"><font face="C&#111;nsolas" size="2"><strong>}<br></strong></font></font><br>Two additional issues. <br>&nbsp;&nbsp; 1) We recently changed the import/export method names from 'import' and 'export' to importMetadata/exportMetadata and importEntities/exportEntities to avoid conflict with javascript vNext reserved words.&nbsp; <br><br>&nbsp;&nbsp; 1) In your example you are importing and exporting metadata and data separately. You only really need to import/export the entities; by default, the metadata gets imported and exported with it.&nbsp; The metadata import/export methods are really intended for use cases where you want to create a new empty entityManager with the same metadata as another entityManager. <br><br><br>]]>
   </description>
   <pubDate>Mon, 08 Oct 2012 10:03:17 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3697&amp;PID=14782#14782</guid>
  </item> 
  <item>
   <title>Local storage strategy :   By the wayI want to implement...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3697&amp;PID=14775#14775</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1540" rel="nofollow">kolpation</a><br /><strong>Subject:</strong> 3697<br /><strong>Posted:</strong> 08-Oct-2012 at 1:18am<br /><br />By the way&nbsp;I want to implement this algorithm:<div>&nbsp;</div><div>-make remote query</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -if it fails make local query</div><div>-save to local storage</div>]]>
   </description>
   <pubDate>Mon, 08 Oct 2012 01:18:51 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3697&amp;PID=14775#14775</guid>
  </item> 
  <item>
   <title>Local storage strategy :   I&amp;#039;ve put two functions...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3697&amp;PID=14774#14774</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1540" rel="nofollow">kolpation</a><br /><strong>Subject:</strong> 3697<br /><strong>Posted:</strong> 08-Oct-2012 at 1:17am<br /><br />I've put two functions in my dataservice.js file:<div></div><div>function saveToLocalStorage() {<br>&nbsp;var metadataAsString = manager.metadataStore.export();<br>&nbsp;window.localStorage.setItem("metadata", metadataAsString);<br>&nbsp;var storageName = "entities";<br>&nbsp;var exportData = manager.export();<br>&nbsp;window.localStorage.setItem(storageName, exportData);<br>};<br>function getFromLocalStorage() {<br>&nbsp;var metadataFromStorage = window.localStorage.getItem("metadata");<br>&nbsp;manager.metadataStore.import(metadataFromStorage);<br>&nbsp;var bundleFromStorage = window.localStorage.getItem("entities");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;manager.import(bundleFromStorage);<br>};</div><font size="2" face="C&#111;nsolas"><font size="2" face="C&#111;nsolas"><p>I think they work. But where to call these functions?</p><div></div>I've put the call to saveToLocalStorage in saveChanges function like:<div></div>function saveChanges() {<br>&nbsp;<strong>saveToLocalStorage();<br></strong>&nbsp;if (manager.hasChanges()) {<br>&nbsp;&nbsp;manager.saveChanges()<br>&nbsp;&nbsp;&nbsp;.then(function (saveResult) {<br>&nbsp;&nbsp;&nbsp;&nbsp;logger.success("# of Records saved = " + saveResult.entities.length);<br>&nbsp;&nbsp;&nbsp;&nbsp;logger.log(saveResult);<br>&nbsp;&nbsp;&nbsp;})<br>&nbsp;&nbsp;&nbsp;.fail(handleSaveError);<br>&nbsp;} else {<br>&nbsp;&nbsp;logger.info("Nothing to save");<br>&nbsp;};<br>};<div>&nbsp;</div><div>I think it works &amp; saves. But I can't figure where to put getFromLocalStorage() call in a situation where the connection is broken. You can give your example in BreezeDocCode project example. I try to make it work :)</font></font></div>]]>
   </description>
   <pubDate>Mon, 08 Oct 2012 01:17:08 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3697&amp;PID=14774#14774</guid>
  </item> 
  <item>
   <title>Local storage strategy : When you say it doesn&amp;#039;t work,...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3697&amp;PID=14772#14772</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1524" rel="nofollow">jtraband</a><br /><strong>Subject:</strong> 3697<br /><strong>Posted:</strong> 06-Oct-2012 at 11:59am<br /><br />When you say it doesn't work, what is the problem? What was the code you tried to put in the error handler?<br><br>Export/import is described in more detail here: <a href="http://www.breezejs.com/&#100;ocumentati&#111;n/exportimport" target="_blank">http://www.breezejs.com/documentation/exportimport&nbsp;</a><br><br>But, I think the short answer is that in order to store the data into the cache after each of your queries and saves, you would write something like this.<br><br><code =" plain">var exportedData = manager.exportEntities();</code><br><code =" plain">window.localStorage.setItem("myLocalStorageName", exportedData);</code><br><br>With this code being executed in both the query or save promise 'then()' callback.<br><br>Then, when you detect a 'lost' connection, you could restore the data like this<br><br><div ="c&#111;ntainer"><div ="c&#111;ntainer"><div ="line number1 index0 alt2"><code =" keyword">var</code> <code =" plain">importedData = window.localStorage.getItem("myLocalStorageName");</code></div><div ="line number2 index1 alt1"><code =" plain">manager.importEntities(importedData);</code></div></div></div><br>or you could import it into a completely new EntityManager.<br><br>One thing to remember, if you have lost your connection, you might want all future queries (until the connection comes back) to go to the local cache by default.&nbsp; This can be accomplised by calling <br><br>manager.defaultQueryOptions = new QueryOptions({ fetchStrategy: FetchStrategy.FromLocalCache });<br><br>Going forward, one of the features we've been considering is raising an EntityManager event on each 'Save' or 'Query'; with this you could simply store the exported cache each time the event was called instead of having to add this code to the callback of each query or save.<br><br>Please feel free to add your vote to this feature using the feedback mechanism on the web site. ( small icon on the right side of any Breeze website page labeled "Feedback").&nbsp; This allows other breeze users to vote on the feature and obviously helps us decide which ones to work on next.&nbsp;   <br><br><br><br>]]>
   </description>
   <pubDate>Sat, 06 Oct 2012 11:59:34 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3697&amp;PID=14772#14772</guid>
  </item> 
  <item>
   <title>Local storage strategy : Can you suggest me a strategy...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3697&amp;PID=14765#14765</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1540" rel="nofollow">kolpation</a><br /><strong>Subject:</strong> 3697<br /><strong>Posted:</strong> 06-Oct-2012 at 5:49am<br /><br /><div style="color: rgb34, 34, 34; font-family: arial, sans-serif; font-size: 13px; line-height: normal; ">Can you suggest me a strategy to cache all data to local storage after every fetch and save transaction and restore it from local if there is no connection at some point.</div><div style="color: rgb34, 34, 34; font-family: arial, sans-serif; font-size: 13px; line-height: normal; ">I want the program works online but if the connection is broken it has to load from local storage. I know you have export and import functionality. I tried to put them in error handlers. But this is not the way, it doesn't work. What is the best practice?</div>]]>
   </description>
   <pubDate>Sat, 06 Oct 2012 05:49:15 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3697&amp;PID=14765#14765</guid>
  </item> 
 </channel>
</rss>