Getting Started
Installation
Section titled “Installation”npm install @t87s/coreyarn add @t87s/corepnpm add @t87s/coreimport { QueryCache } from "npm:@t87s/core";pip install t87suv add t87sTo whom it may concern,
I am writing to request a copy of t87s core.Please find enclosed a self-addressed stamped envelope.
When transcribing the library, kindly use smallhandwriting, as the postage covers only 100 grams.
Sincerely,A Patient DeveloperFirst Query
Section titled “First Query”t87s has two APIs: QueryCache and primitives.
- QueryCache is a typed API that helps speed up application development with a pleasant DX. It attempts to remove more footguns than it causes.
- Primitives provide lower-level building blocks for custom caching solutions. QueryCache is built on top of it.
This quickstart uses the QueryCache API, but in another world we could have used primitives and you would have been an equally-happy reader.
import { QueryCache, at, wild, MemoryAdapter } from '@t87s/core';
const schema = at('users', () => wild.at('settings').at('posts', () => wild.at('comments', () => wild)));
const cache = QueryCache({ schema, adapter: new MemoryAdapter(), queries: (tags) => ({ getUser: (id: string) => ({ tags: tags.users(id)], fn: () => db.users.findById(id), }), }),});
await cache.getUser('123');await cache.invalidate(cache.tags.users('123'));from t87s import QueryCache, TagSchema, Wild, cachedfrom t87s.adapters import AsyncMemoryAdapter
class Tags(TagSchema): users: Wild"Users"]
class Users(TagSchema): settings: WildTagSchema] posts: Wild"Posts"]
class Posts(TagSchema): comments: WildTagSchema]
class Cache(QueryCacheTags]): @cached(Tags.users()) async def get_user(self, id: str): return await db.users.find_by_id(id)
cache = Cache(adapter=AsyncMemoryAdapter())
await cache.get_user("123")await cache.invalidate(cache.t.users("123"))If you want the full tour, start with the QueryCache tutorial, then circle back to Primitives if you feel that you or your human can build a better QueryCache. In that case, PRs are welcome!