A lightspeed, lightweight client-side cache for GraphQL.
Welcome to LightQL. A lightspeed, lightweight client-side cache for GraphQL.
Explore the docs »
View Demo
LightQL is an easy-to-use super fast and lightweight Javascript library providing a client-side caching solution for GraphQL. Use LightQL for extremely low latency retrieval of persistent cache data.
Head over to the home page of our website (lightql.com)
Using our demo is a simple 2-step process.
First, press the “Run the demo” button to see the resulting GraphQL query result. If you divert your attention to the metrics box down below you will see an uncached run time populate. This statistic represents the time it took to make a GraphQL fetch and receive the response data. You can also see the spike in time upwards on the graph provided on the right.
If you press the run query button again you will notice that your cached run time metric will now render. The graph on the right will also dive down as the response time has significantly decreased. The uncached run time should never change after this, as we are now retrieving your data from the cache every instance forward showing our super lightning speed of retrieval!
*A small disclaimer: It should be noted that your first query will have a significantly higher runtime than the other first queries because it is establishing a connection.
npm install lightql-cache
import { LRUCache, DoublyLinkedList, DLLNode } from ‘lightql-cache’;
const cache = new LRUCache(3, 'http://localhost:3000/graphql');
const graphqlQueryStr = ` {
user {
user_name,
song_name,
movie_name
}
}`;
const callLightQL = async () => {
const cacheGet = await cache.get(graphqlQueryStr, variables);
};
LightQL caches responses to GraphQL formatted queries as key-value object representations of the graph’s nodes, making it possible to satisfy GraphQL queries from a cached data store.
When your application needs data, it checks the cache first to determine whether the data is available. If the data is available (a cache hit), the cached data is returned, and the response is issued to the user. If the data isn’t available (a cache miss), the database is queried for the data. The cache is then populated with the data that is retrieved from the database, and the data is returned to the user. The benefit of this strategy is that the cache contains only data that the application actually requests, keeping the cache size cost-effective. Further, this increases cache hits, reduces network calls, and significantly reduces the overall runtime and latency.
LightQL’s LRUCache function creates an instance of the LightQL cache. A capacity and GraphQL endpoint are the two necessary arguments to pass in to this function. The LRUCache consists of a HashMap and Doubly-Linked List to store GraphQL query responses. The combination of these two data structures offer best-case scenario time complexity (O(1)) for insertion, deletion, and lookup.
function LRUCache(capacity, graphqlEndpoint) {
this.capacity = Math.floor(capacity);
this.map = new Map();
this.dll = new DoublyLinkedList();
this.graphqlEndpoint = graphqlEndpoint;
}
LightQL leverages localForage and IndexedDB to persist cached data between sessions. localForage is a fast and simple storage library for Javascript. localForage leverages asynchronous storage through IndexedDB, a JS-based object-oriented database that runs in your browser, with a simple, localStorage-like API. Whenever you run a query through LightQL, the capacity, HashMap, Doubly-Linked List, and graphqlEndpoint are loaded into memory if available through the localForage setItem method:
localforage.setItem();
Additionally, before returning data to users, LightQL writes our cache data structures and graphqlEndpoint to our persistent memory in IndexedDB through the localForage getItem method:
localforage.getItem();
Developers can entrust LightQL to handle their GraphQL caching needs simply and effectively, so they can focus on working what matters most.
Upcoming planned features:
Here at LightQL we created our open-source project with the intention to further expand upon and improve this tool for years to come.
That's where the community comes in! If you have an idea that might make LightQL better we always encourage contributions. Simply follow the steps below to submit the changes you would make.
git pull origin dev
)git checkout -b <yourFeatureName>
)git add .
)git commit -m "<your comment>"
)git merge dev
)git push origin <your feature branch name>
)Distributed under the MIT License. See LICENSE.txt
for more information.
Visit https://lightql.com/aboutus to reach out to the team!