23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

efore setting up new defaults. As mentioned before, it’s also possible to migrate state from a<br />

background task. (See Chapter 13.)<br />

Generally speaking, local and temp app data are the same—they have the same APIs and are stored<br />

in parallel folders. Temp, however, doesn’t support settings and settings containers. The other difference<br />

is that the contents of your temp folder (along with the <strong>HTML</strong>5 app cache) are subject to the Windows<br />

Disk Cleanup tool. This means that your temp data could disappear at any time when the user wants to<br />

free up some disk space. You could also employ a background task with a maintenance trigger for<br />

doing cleanup on your own (again see Chapter 13, in the section “Tasks for Maintenance Triggers.”)<br />

For these reasons, temp should be used for storage that optimizes your apps performance but not<br />

for anything that’s critical to its operation. For example, if you have a JSON file in your package that you<br />

parse or decompress on first startup such that the app runs more quickly afterwards, and you don’t<br />

make any changes to that data from the app, you might elect to store that in temp. The same is true for<br />

graphical resources that you might have fine-tuned for the specific device you’re running on; you can<br />

always repeat that process from the original resources, so it’s another good candidate for temp data.<br />

Similarly, if you’ve acquired data from an online service as an optimization (that is, so that you can just<br />

update the local copy incrementally), you can always reacquire it. This is especially helpful for providing<br />

an offline experience for your app, though in some cases you might want to let the user choose to save<br />

it in local instead of temp (an option that would appear in Settings along with the ability to clear the<br />

cache).<br />

Sidebar: <strong>HTML</strong>5 App Cache<br />

Store apps can employ the <strong>HTML</strong> 5 app cache as part of an offline/caching strategy. It is most<br />

useful in iframe web context elements where it can be used for any kind of content. For example,<br />

an app that reads online books can show such content in an iframe, and if those pages include<br />

app cache tags, they’ll be saved and available offline. In the local context, the app cache works for<br />

nonexecutable resources like images, audio, and video, but not for <strong>HTML</strong> or JavaScript.<br />

IndexedDB and Other Database Options<br />

Many forms of local app data are well suited to being managed in a database. In Windows Store apps,<br />

the IndexedDB API is available through the window.indexedDB and worker.indexedDB objects. For<br />

complete details on using this feature, I’ll refer you to the W3C specifications, the Indexed Database API<br />

reference for Store apps, and the IndexedDB sample.<br />

Although an IndexedDB database is stored within your app’s local app data, be aware that there are<br />

some limitations because there isn’t a means through which the app or the system can shrink a database<br />

file and reclaim unused space:<br />

329

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!