npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

medhira-rn-styles-cache

v0.0.2

Published

MEDHIRA - React Native styles caching with LRU cache

Readme


Why this exists

StyleSheet.create() optimizes style objects, but dynamic styles recreated every render waste work and memory. This package caches flattened styles in an LRU cache keyed by a stable hash, so identical style shapes reuse the same registered style reference.

| You get | Details | |--------|---------| | LRU caching | Configurable max entries (default 500) | | Stable keys | Canonical serialization — property order does not matter | | Theme keys | Separate LRU buckets per theme string | | RN-native flattening | Uses StyleSheet.flatten for arrays and nested styles |

Install

# Expo
npx expo install medhira-rn-styles-cache

# React Native
npm install medhira-rn-styles-cache

Peer dependencies: react, react-native (tested with RN 0.85.x, React 19.x)

Quick start

import { View } from 'react-native';
import { getCachedStyle } from 'medhira-rn-styles-cache';

const dynamicStyle = getCachedStyle({
  width: isWide ? 200 : 100,
  padding: 12,
});

export function Card() {
  return <View style={dynamicStyle} />;
}

How it works

sequenceDiagram
  participant App as Component
  participant API as getCachedStyle
  participant Flat as StyleSheet.flatten
  participant LRU as LRU per theme
  participant SS as StyleSheet.create

  App->>API: style + optional theme
  alt registered style ID (number)
    API-->>App: return as-is
  else style object
    API->>Flat: flatten arrays
    API->>LRU: lookup stable hash
    alt cache hit
      LRU-->>App: cached style
    else cache miss
      API->>SS: create style
      API->>LRU: store
      API-->>App: new style
    end
  end

Full architecture: docs/architecture.md

API

| Function | Description | |----------|-------------| | getCachedStyle(style, theme?) | Cache one style | | getCachedStyles(map, theme?) | Cache a named map of styles | | prewarmStyles(styles, theme?) | Fill cache at startup | | clearStyleCache(theme?) | Clear all themes, or one theme | | configureStyleCache({ max }) | Set LRU max size | | getStyleCacheStats() | { size, max, themes } |

import {
  configureStyleCache,
  getCachedStyle,
  getCachedStyles,
  prewarmStyles,
  clearStyleCache,
} from 'medhira-rn-styles-cache';

configureStyleCache({ max: 1000 });

const light = getCachedStyle({ color: '#000' }, 'light');
const styles = getCachedStyles({ row: { flexDirection: 'row' } }, 'light');

prewarmStyles([{ flex: 1 }, { padding: 8 }]);
clearStyleCache('light');

Platform-specific styles: use standard spread — ...Platform.select({ ios: {...}, android: {...} }) inside your style object before passing it to getCachedStyle.

See the API reference and examples.

When to use

| Use this library | Prefer module-level StyleSheet.create | |------------------|----------------------------------------| | Styles depend on props/state | Styles are fully static | | Shared dynamic tokens (theme, density) | One-time app shell styles |

Contributing

Contributions are welcome. See CONTRIBUTING.md.

Support

License

MIT © MEDHIRA