cache management
This commit is contained in:
parent
ab4accfc8c
commit
fa7e5b1c62
2 changed files with 268 additions and 108 deletions
106
README.md
106
README.md
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# Rugreefer
|
||||
|
||||
**Rugreefer** is a Dart library for retrieving metadata about geographic coordinates from a [dopecarpet](http://github.com/TheRandonauts/dopecarpet) server. It converts coordinates into a geohash, fetches a gzipped GeoJSON file from the API, and extracts relevant spatial data such as polygons and lines. The library also supports caching with optional expiration to improve performance.
|
||||
Rugreefer is a Dart library for retrieving metadata about geographic coordinates from a [dopecarpet](http://github.com/TheRandonauts/dopecarpet) server. It converts coordinates into a geohash, fetches a gzipped GeoJSON file from the API, and extracts relevant spatial data such as polygons and lines. The library also supports caching with optional expiration to improve performance.
|
||||
|
||||
## Features
|
||||
- Converts latitude/longitude to geohash (precision: 4 characters)
|
||||
|
|
@ -10,10 +10,10 @@
|
|||
- Extracts relevant metadata from polygons and lines
|
||||
- Supports caching for performance optimization
|
||||
- Optional cache expiration (default: 14 days)
|
||||
- Works in **Flutter** (mobile, desktop, web)
|
||||
- Works in Flutter (mobile, desktop, web)
|
||||
|
||||
## Installation
|
||||
Add **rugreefer** to your `pubspec.yaml`:
|
||||
Add rugreefer to your `pubspec.yaml`:
|
||||
|
||||
```yaml
|
||||
dependencies:
|
||||
|
|
@ -29,17 +29,23 @@ flutter pub get
|
|||
|
||||
## Usage
|
||||
|
||||
### **Basic Example**
|
||||
### Basic Example
|
||||
|
||||
To create an instance of `RugReefer`, provide the required parameters:
|
||||
|
||||
```dart
|
||||
import 'package:rugreefer/rugreefer.dart';
|
||||
|
||||
void main() async {
|
||||
final lookup = RugReefer(
|
||||
apiUrl: 'http://localhost:8000/get_geodata/?format=geojson&geohash=',
|
||||
enableCacheExpiration: true,
|
||||
);
|
||||
final rugReefer = RugReefer(
|
||||
apiUrl: 'https://example.com/api', // API endpoint for geospatial data
|
||||
categoryMap: 'assets/categories.json', // Path to the JSON asset for category mapping
|
||||
enableCacheExpiration: true, // Optional: Enable cache expiration (default: false)
|
||||
cacheExpirationDuration: Duration(days: 14), // Optional: Cache expiration duration (default: 14 days)
|
||||
cacheSizeThreshold: 20 * 1024 * 1024, // Optional: Cache size threshold in bytes (default: 20MB)
|
||||
);
|
||||
|
||||
final results = await lookup.lookup(30.5735040, 34.453125);
|
||||
final results = await rugReefer.lookup(30.5735040, 34.453125);
|
||||
print(results);
|
||||
}
|
||||
```
|
||||
|
|
@ -62,13 +68,83 @@ Example Output:
|
|||
]
|
||||
```
|
||||
|
||||
### **Custom Cache Settings**
|
||||
## Available Methods
|
||||
|
||||
### 1. Lookup Metadata
|
||||
Perform a geospatial metadata lookup for a given latitude and longitude.
|
||||
|
||||
```dart
|
||||
final lookup = RugReefer(
|
||||
apiUrl: 'http://your-api.com/get_geodata/?format=geojson&geohash=',
|
||||
enableCacheExpiration: true,
|
||||
cacheExpirationDuration: Duration(days: 7),
|
||||
);
|
||||
Future<Map<String, Map<String, List<String>>>> lookup(
|
||||
double latitude,
|
||||
double longitude, {
|
||||
double distanceThreshold = 10.0, // Optional: Distance threshold in meters (default: 10.0)
|
||||
});
|
||||
```
|
||||
|
||||
Example:
|
||||
```dart
|
||||
final metadata = await rugReefer.lookup(37.7749, -122.4194);
|
||||
print(metadata);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2. Get Current Cache Size
|
||||
Get the total size of the cache in bytes.
|
||||
|
||||
```dart
|
||||
Future<int> getCurrentCacheSize();
|
||||
```
|
||||
|
||||
Example:
|
||||
```dart
|
||||
final cacheSize = await rugReefer.getCurrentCacheSize();
|
||||
print("Cache size: ${cacheSize / 1024 / 1024} MB");
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3. List Cached Files
|
||||
List all currently cached files with their sizes and last access times.
|
||||
|
||||
```dart
|
||||
Future<List<Map<String, dynamic>>> listCachedFiles();
|
||||
```
|
||||
|
||||
Example:
|
||||
```dart
|
||||
final cachedFiles = await rugReefer.listCachedFiles();
|
||||
for (var file in cachedFiles) {
|
||||
print("File: ${file['file']}, Size: ${file['size']} bytes, Last Access: ${file['lastAccess']}");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4. Delete a Specific Cached File
|
||||
Delete a specific cached file by its geohash.
|
||||
|
||||
```dart
|
||||
Future<void> deleteCachedFile(String geohash);
|
||||
```
|
||||
|
||||
Example:
|
||||
```dart
|
||||
await rugReefer.deleteCachedFile('u4pru');
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 5. Clear the Entire Cache
|
||||
Delete all cached files and remove their last access times.
|
||||
|
||||
```dart
|
||||
Future<void> clearCache();
|
||||
```
|
||||
|
||||
Example:
|
||||
```dart
|
||||
await rugReefer.clearCache();
|
||||
```
|
||||
|
||||
## Author
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue