Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 2a628b9

Browse files
committed
updating readme
:
1 parent b9f9349 commit 2a628b9

File tree

1 file changed

+109
-5
lines changed

1 file changed

+109
-5
lines changed

README.md

+109-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Pre-requisites:
2020
* via nu-get, install the following packages:
2121
* Newtonsoft.json
2222
* SQLite.Net-PCL
23-
* SQLite.Net.Platform.* where * is the runtime for the current application
23+
* SQLite.Net.Platform.* (where * is the runtime for the current application)
24+
* LinqExtender
2425

2526

2627

@@ -41,12 +42,11 @@ This library is implemented with a clean separation between blocking synchronous
4142
Client kinveyClient = new Client.Builder(appKey, appSecret).build();
4243

4344
##### add offline to the client builder
44-
Note the addition of two new builder methods (which will be refactored and simplified) to add the local database path location as well as a platform specific implementation of the sqlite.net pcl.
45+
Note the addition of two new builder methods to add the local database path location as well as a platform specific implementation of the sqlite.net pcl.
4546

4647
kinveyClient = new Client.Builder(appKey, appSecret)
47-
.setFilePath(Android.OS.Environment.ExternalStorageDirectory.ToString ())
48-
.setOfflinePlatform(new SQLitePlatformAndroid())
49-
.build();
48+
.setFilePath(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal))
49+
.setOfflinePlatform(new SQLitePlatformAndroid()).build();
5050

5151

5252

@@ -98,6 +98,110 @@ Note the addition of two new builder methods (which will be refactored and simpl
9898
});
9999
}
100100
});
101+
102+
### Querying
103+
104+
Querying can be performed through standard LINQ operators, where an instance of `AppData` can be used as the queryable object. The Kinvey library provides a subset of LINQ which includes most of the core functionality. For example, you cannot perform Join operations due to the nature of a nosql datastore. The library does support Lambda operations, as well as sorting, where clauses, and logical operators.
105+
106+
For example, a query to get all Entites where a field called `last name` is equal to `smith` can be written as follows:
107+
108+
var query = from cust in testData
109+
where cust.lastname == "smith"
110+
select cust;
111+
112+
113+
More complex queries are also supported, such as:
114+
115+
var query = from cust in testData
116+
where (cust.ID == "10" && cust.Name == "Billy") || (cust.ID == "1" && cust.Name == "Charlie")
117+
select cust;
118+
119+
120+
121+
### Caching and Offline
122+
Caching functionality is provided as in-memory implementation, meaning that cached data will only be available per use of the application. Offline functionality utilizes SQLite to maintain a local copy of entities, as well as a queue of pending requests. This data is persisted between uses of the application, and will perform any queued up requests once any request has been successfully completed.
123+
124+
Both features are accessed through very similar methods on an Appdata instance, essentially only requiring an implementation of a `Store`, as well as a Policy to use. See below for details about the provided caching and offline policies.
125+
126+
Both caching and offline can be used at the same time, allowing for very quick responses to commonly repeated requests, and a fail-over in case a network connection is lost.
127+
128+
####Enabling Caching and Offline
129+
130+
The Client.Builder will require both a reference to the local filesystem, as well as a platform specific implementation of the SQLite.Net-PCL. For Android, the following will store the database in private local storage:
131+
132+
kinveyClient = new Client.Builder(appKey, appSecret)
133+
.setFilePath(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal))
134+
.setOfflinePlatform(new SQLitePlatformAndroid()).build();
135+
136+
137+
138+
To enable caching:
139+
140+
//resuse this cache object!
141+
InMemoryCache<MyEntity> myCache = new InMemoryCache<MyEntity>();
142+
143+
//get a reference to AppData
144+
AsyncAppData<MyEntity> entityCollection = kinveyClient.AppData<MyEntity>("MyCollection", typeof(MyEntity));
145+
146+
//enable caching
147+
entityCollection.setCache (myCache, CachePolicy.CACHE_FIRST);
148+
149+
150+
To enable offline:
151+
152+
//get a reference to AppData
153+
AsyncAppData<MyEntity> entityCollection = kinveyClient.AppData<MyEntity>("MyCollection", typeof(MyEntity));
154+
155+
//enable offline, no need to reuse SQLiteOfflineStore, all instances share a database
156+
entityCollection.setOffline(new SQLiteOfflineStore<MyEntity>(), OfflinePolicy.LOCAL_FIRST);
157+
158+
159+
### Cache Policies
160+
161+
* `CachePolicy.NOCACHE` - This policy will not use any caching, and will execute every request online.
162+
163+
Use this policy if your application is dependant on data that is shared between multiple users and always needs to be up to date.
164+
165+
166+
* `CachePolicy.CACHEONLY` - This policy will only retrieve data from the cache, and will not use any network connection.
167+
168+
Use this policy in combination with another policy, to allow for quick response times without requiring a network connection for specific operations.
169+
170+
171+
* `CachePolicy.CACHEFIRST` - This policy will first attempt to retrieve data from the cache. If the data has been cached, it will be returned. If the data does not exist in the cache, the data will be retrieved from Kinvey's Backend and the cache will be updated.
172+
173+
Use this policy if your application can display data that doesn't change very often but you still want local updates.
174+
175+
176+
* `CachePolicy.CACHEFIRST_NOREFRESH` - This policy will first attempt to retrieve data from the cache. If the data has been cached, it will be returned. If the data does not exist in the cache, the data will be retrieved from Kinvey's Backend but the cache will not be updated with the new results.
177+
178+
Use this policy if you want to set default results, however if a request is made that cannot return these defaults a live request will be made (without modifying those default values)
179+
180+
181+
* `CachePolicy.NETWORKFIRST` - This policy will execute the request on the network, and will store the result in the cache. If the online execution fails, the results will be pulled from the cache.
182+
183+
Use this policy if you application wants the latest data but you still want responsiveness if a connection is lost
184+
185+
186+
187+
###Offline Policies
188+
189+
190+
* `OfflinePolicy.ONLINE_FIRST` - This policy will attempt to execute the request online first, and if that is successful will update the local store with the results. If the request fails due to connectivity issues, then the request will be executed against the local store. If it fails for any other reason such as an Authorization Error, the onFailure callback will be called.
191+
192+
Use this policy if your application's data is constantly changing on the backend, but you want to support offline mode.
193+
194+
195+
* `OfflinePolicy.LOCAL_FIRST` - This policy will attempt to execute the request against the local store first. If the request is a Get, and the data cannot be found in the local store, then an online request will be attempted. If that suceeds, the store will be updated, and onSuccess will be called. If that fails, then onFailure will be called. For save requests, the local store will be updated and the entity will be returned through the onSuccess callback.
196+
197+
Use this policy if each user has their own data, and updates are not constantly required from your backend.
198+
199+
200+
* `OfflinePolicy.ALWAYS_ONLINE` - This policy will not use any local storage or queueing, and will execute every request online. If no network connection is available, errors will be returned through the onFailure callback.
201+
202+
Use this policy if your application is fully dependant on data in the backend, and data cannot be stored locally.
203+
204+
101205

102206

103207
## License

0 commit comments

Comments
 (0)