welcome to the local storage session in the session
we'd like to discuss a number of online and offline interaction patterns and
here we'll be focusing a little bit on the offline interaction pattern because
that is where we would need local storage and inside Outsystems 10 local
storage entities are going to be able to exist on the device and they will enable
all of our offline and caching scenarios so for us to be able to have nice
offline interaction patterns and design for that type of user experience
we're going to need these local storage entities now we can create them
relatively easily if they need to duplicate an existing database entity or
we can go ahead and create them from scratch because they may be a mapping of
several different types of entities once we have local storage entities we may
need to initialize them with some original data and once they are
initialized and ready
depending on whether or not users can update that local storage information
and it needs to be reported back we may need to be able to synchronize the data
with the server so local storage entities are very valuable very
useful
we just have to think a little bit about the different types of things we have to
do to work with them appropriately now the last thing that will talk about is
securing locally stored data once we decide that some of the data can exist
on the device we begin to create another type of security problem and we want at
least be aware of the opportunities or risks better there and we want to make
sure that we have a couple ways of securing the data that is stored locally
so let's get started talking about these topics if we think about the typical
interaction patterns if we were creating something like our to-do list and we
just wanted to store everything on the server then our aggregate that's going
to fetch data will fetch the data from the restful end point it'll make the call to
the server the server will get the information and send it back and then
we'll be able to render to-do's in the list
and be able to work with them but if we want them to be local and not actually
come off of the server then we might have to change that to be able to say
okay we'll get some set of to do is to start with and then from there on those
to do is will be stored in local storage and will retrieve all the news from
local storage and we make updates or changes will be updated or changed in
local storage and if we need to synchronize maybe sometime later we
would go ahead and synchronize them but the difference here is the regular
interaction stores things in the database on the server and here we'd be
storing things locally on the device and in a number of cases the storage can be
different but it's usually something like sql light so when we talk about
local storage we have the capability of creating local storage entities and
those are the entities that are going to enable our offline scenarios they are
stored on the device so we have the capability of fetching them anytime
it doesn't matter if we're online or offline we will have access to the data
because it is there now they're actually number different use cases to use local
storage we continually think of offline because that's the major type of
interaction that is difficult to do without local storage but once we have
local storage because you have the capability of storing data locally you
can create your own standalone app that doesn't ever need to talk to the server
at all
you can also use local storage of the cache to go ahead and store certain bits
of data that rarely change so why not download at once instead of every time
we go and creator start the app or close the app have to go and get that data
again if we store it locally and just check for changes the caching and the
performance of the app could potentially be even faster and then certainly the
big one that were worried about is the offline use case so the offline use
case we'll use local storage entities to store the data locally and then we'll
begin making choices as to
should the data store locally be read only or can be changed
will it be all of the data or will it be a subset of the data and will begin to
answer a number of those questions depending on the type of app and the
design that were worried about now will begin to think about the details of
local storage entities and Outsystems we already mentioned the stored on the
device but they can also be created from database entities so when we look at the
database entities there's a set of them and if we come to the local storage
entities we can ask it to add an entity from the database and that will
basically duplicate the database entity and create a local copy of that so
if we had to do's they would be called local to do's and they would have the
exact same set of attributes as the ones in the database so it matches the
entity directly and that would make it much easier for us to map the syncing
process now one thing that is a little strange for the local storage entities
if you've worked with Outsystems before you may know that we have the capability
of previewing data from database entities and that we can bootstrap so
there's an advanced capability where we can sort of initializing bootstrap the
database entity with some information from an Excel spreadsheet local storage
entities don't have either of those available and the reason we can't save
you the data is because when were in the development environment working were
were actually talking to the Outsystems server and the Outsystems server can't
talk back to the device and the local storage in the device to be able to give
you what is the data in the device itself and in the same way without sort
of basically bootstrapping some sort of database information and then
transferring into local storage there's no way we can go ahead and create a set
of actions that will directly run on the device and automatically create local
storage there so these two things that you may be accustomed to to kind of help
us get started with development and have some data that we can work with
those are not going to be available directly on local storage entities and
this brings us to the fact that will need to initialize the local storage and
sometimes just having the local storage types is good enough because the user
will be creating all of the data they're the ones that generate the data and will
keep updating the data because the data is there and it's personal and all of it
is available many times will need some set of data for an app that comes from
the server because the application has more information and data that isn't
user-specific or maybe team specific because what we're really talking about
here is potentially a number of users having devices and access to an
application that has distributed data where people are sharing information so
we would need to originally initialize local storage if it needs to have some
sort of initial set of data so when we think about initializing local storage
we can have a synchronization button and the synchronization could always say hey
we're just going to synchronize the data the same way every time so it's
basically an initialization itself if not and there may be some way that we
have to initialize data and we can either do that as a single configuration
step or sometimes we can just create that as part of the install process for
the application so there are a couple choices as to how we can go ahead and
approach that but just as an example here let's say we decided to create a
button like download data to local storage that would allow us to
initialize and get everything from the server so our download data on click for
this button would then need to trigger the offline data sync and triggering
offline data sync calls the client action offline data sync and the
offline data sync client action calls the server data sync server
action and then inside that server data sync we may have a number of different
ways to do synchronization in this particular case because we are
initializing it we want to get all of the data that we need from the server to
initialize local storage
so we might make a call that says get all data and when get all data is called
then it will go ahead and get all of the data and then return it so in this
particular case the server data sync will make the call the get all data will
be run and then we'll get the information back and we'll have initial
local storage done so
initializing local storage will use part of the data synchronization framework
and we're going to talk about that framework a lot more in one of the next
sessions now once we have our local storage initialized then after that point we
can make the decision as to whether or not you know if we're offline we'll
update local storage or if we're online we might make calls to the server so it
becomes more of a design capability
once we know we can get to local storage store some of the information there and
it may already have data that we need initialized so once all the data is here
at different times we may choose to synchronize we may say hey whenever I
open the app after it's been closed I'd like it to go ahead and synchronize the
data so we can have background processes and again part of a synchronization
framework worrying about things like synchronizing on login synchronizing
on resume synchronizing when we open the app so and depending on what we need
that synchronization may be different because depending on what type of
scenario we're thinking about the synchronization maybe all of the data or
part of the data so we're never quite sure what the server is going to do when
we synchronize their maybe different choices that are available now that gets
us a good introduction to local storage we understand that we can create
different types of entities and that we may need to initialize and then worry
about synchronization but this does mean that local storage entities will be
locally stored on the device and in general from a security standpoint it's
probably best practice to say we should avoid storing sensitive data
on the device devices can be lost or stolen and that creates risk of people
being able to get to that type of data so during our design we should really
think about having the minimum subset of data to allow the key offline tasks that
we need but not store any more sensitive data than that if we do that what are
the different ways we could secure that sensitive data
well if we have very small amounts of sensitive data you can actually use the
devices keystore or keychain and you can go ahead and store small bits of data in
that and that's something that's available on the device and it's
available all the time to be able to use that we need the keystore plugin from
the forge but we'd be able to go ahead and store small bits of information
there and that's managed by the device and the operating system itself the
other way we could store small amounts of data is using javascript encryption
so we could get a JavaScript encryption framework and say that before we store
the data will go ahead and encrypted it and then when we need to retrieve the data
will decrypt it after we retrieve it and then we'll have that sensitive data
there now
one problem that sort of generates is that if we're using an encryption
framework there's probably some sort of encryption key and we need to secure
that somewhere to make sure that this encryption and decryption is done safely
a lot of times the encryption key is actually stored in the keystore or the
keychain so sometimes you'll use both of these capabilities together to store
certain bits of data
what if my application has mostly sensitive data and i still need to be
able to keep them safe and I want to do all that so storing large amounts of
sensitive data you can go ahead and encrypt all of the local storage and to
be able to do that you can use the ciphered localstorage plug-in and that
will help you do that so everything in local storage will be encrypted but
obviously to do that there is a performance overhead so every time we
read data and every time we write data it's going to have to be encrypted so
all those data operations may see a performance hit
but that's the trade-off for us making sure that we have sensitive data
completely secure on the device so a number of different scenarios a number
of different ways to worry about having local storage if that data is sensitive
and we'd like to try to avoid that as much as possible we do have the
capability of going ahead and securing it so using these plugins is a key
way to go ahead and make local data more secure
so in this session we talked about local storage and we looked at how online and
offline patterns are a little different local storage entities will enable us to
have these offline interaction patterns that we want the local storage is on the
device it can be created quickly and easily from the database entities that
we've created and we may need to initialize and synchronize the data over
time and we want to be very careful about the types of data that we put on
the device we need to be able to secure that data and that's very important so
hopefully this gives you a good idea of what local storage makes available to us
and the next section we're going to talk about is how to synchronize some of this
data that ends up in local storage