
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@rxdi/cache
Advanced tools

$ npm install @rxdi/cache --save
AppModule:import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {AppComponent} from './app.component';
// Import @rxdi/cache library
import {CacheModule} from '@rxdi/cache';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
// Import CacheModule optional parameters provided at the bottom of readme
CacheModule.forRoot(),
LibraryModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
***NOTE Every cache created by cacheService is treated like a LAYER , so you need to specify layer name like example aboveimport {Component, OnInit} from '@angular/core';
import {BehaviorSubject, Subscription} from 'rxjs';
import {CacheService, CacheLayer, CacheLayerItem} from '@rxdi/cache';
export interface Item {
name: string;
}
export const EXAMPLE_CACHE_LAYER_NAME = 'example-layer';
@Component({
selector: 'app-example',
templateUrl: './example.component.html',
styleUrls: ['./example.component.scss']
})
export class ExampleComponent implements OnInit {
exampleLayer: CacheLayer<CacheLayerItem<Item>>;
exampleLayerItems: BehaviorSubject<CacheLayerItem<Item>[]>;
subscription: Subscription;
constructor(
private cacheService: CacheService
) {}
ngOnInit() {
// Here we define our cache layer name, this method returns instance of class CacheLayer<CacheLayerItem<Item>>
this.exampleLayer = this.cacheService.create<Item>({
name: EXAMPLE_CACHE_LAYER_NAME
});
// inside this.exampleCache you can find object named items returns BehaviorSubject<CacheLayerItem<Item>[]> object type
this.exampleLayerItems = this.exampleLayer.items
// Correct implementation of subscribing to collection of layer items and work inside component with it:
// Recommended way to work with cacheLayer collection items is to create another observable asObservable and use items this way
// Anyway it is better to let angular view model to handle subscription itself ( cartItems | async)
// To work with collection this way you can use collection Instance returned from get above (this.cacheLayer) (Examples Below)
this.subscription = this.exampleLayerItems.asObservable()
.subscribe(items => {
});
// If you try to unsubscribe from this.cacheItems when you leave component state ngOnDestroy(),
// you will loose observable stream from the cache layer and the result will be error ***Check NOTES below***
// Another method is to take values single time only per component initialization
this.exampleLayerItems
.pipe(
take(1)
)
.subscribe(itemCollection => itemCollection
.forEach(item => {
// Because we define interface for this items we have the following autosuggestion from the IDE
const itemName = item.data.name;
})
);
// Put item to current cache defined above
// When there is a new item added to collection cache automatically emits new results to this.exampleLayerItems BehaviorSubject object type
this.createItem({
key:'example-key',
data:{
name:'pesho'
}
});
// Get cached data from added item above will return {data:{ name:'pesho' }}
const exampleData = this.get('example-key');
// Remove item from current layer
this.remove('example-key');
}
createItem(data: any) {
this.exampleLayer.put(data);
}
get(key: string) {
this.exampleLayer.get(key);
}
remove(key: string) {
this.exampleLayer.remove(key);
}
}
import {Injectable} from '@angular/core';
import {CacheService, CacheLayer} from '@rxdi/cache';
import {EXAMPLE_CACHE_LAYER_NAME, Item} from './example.provider';
@Injectable()
export class YourClass {
cacheLayer: CacheLayer<CacheLayerItem<Item>>;
constructor(private:cacheService:CacheService){
this.cacheLayer = cacheService.get<Item>(EXAMPLE_CACHE_LAYER_NAME);
// Now work with this collection the same as example above;
}
}
import {Injectable} from '@angular/core';
import {CacheService} from '@rxdi/cache';
import {EXAMPLE_CACHE_LAYER_NzAME} from './example.provider';
@Injectable()
export class YourClass {
constructor(private:cacheService:CacheService) {
cacheService.remove(EXAMPLE_CACHE_LAYER_NAME);
}
}
import {Injectable} from "@angular/core";
import {CacheService, CacheLayer, CacheLayerItem, CacheServiceConfigInterface} from "@rxdi/cache";
import {Product} from "../core/config/queries/product/product.interface";
export const CART_CACHE_LAYER_NAME = 'cart';
export interface Product {
id: string;
name: string;
title: string;
price: string;
quantity: number;
completed: boolean;
categoryId: number;
}
@Injectable()
export class CartProvider {
cacheLayer: CacheLayer<CacheLayerItem<Product>>;
items: BehaviorSubject<CacheLayerItem<Product>[]>;
constructor(private cacheService: CacheService) {
this.cacheLayer = this.cacheService.create<Product>(<CacheLayerInterface>{
name: CART_CACHE_LAYER_NAME,
config: <CacheServiceConfigInterface>{
localStorage: true,
maxAge: 10000,
cacheFlushInterval: 10000
}
});
this.items = this.cacheLayer.items;
}
putToCart(product: Product) {
this.cacheLayer.put({
key:product.id,
data: product
});
}
removeFromCart(product: Product) {
this.cacheLayer.remove(product.id);
}
}
import {Component, OnInit} from '@angular/core';
@Component({
selector: 'app-cart',
templateUrl: './cart.component.html',
styleUrls: ['./cart.component.scss']
})
export class CartComponent implements OnInit {
cartItems: BehaviorSubject<CacheLayerItem<Product>[]>;
cacheLayer: CacheLayer<CacheLayerItem<Product>>;
constructor(private cartProvider: CartProvider) {}
ngOnInit() {}
remove(product: Product) {
this.cartProvider.removeFromCard(product)
}
updateItem(product: Product) {
this.cartProvider.putToCart(product);
}
}
<div *ngFor="let product of (cartProvider.items | async)">
{{item.key}} // is cache identity
{{item.data.id}} // Cached data from current item from card layer Observable
<-- removeKey in my case item.id is unique so i should remove item id -->
<button (click)="remove(product)">Remove item</button>
</div>
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {AppComponent} from './app.component';
// Import rxdi/cache
import {CacheModule, CacheConfigInterface} from '@rxdi/cache';
// Define global configuration
// You can set localStorage to true it will cache every layers like a localStorage item
// By default localStorage is set to false
export const CACHE_DI_CONFIG = <CacheConfigInterface>{
localStorage: true,
maxAge: 15 * 60 * 1000, // Items added to this cache expire after 15 minutes
cacheFlushInterval: 60 * 60 * 1000, // This cache will clear itself every hour
}
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
// Import CacheModule with CACHE_DI_CONFIG;
CacheModule.forRoot(CACHE_DI_CONFIG)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
CacheService.create<any>({name: 'layer-name', settings?: CacheLayerInterface})
Optional you can define custom settings for every layer that you create just insert CacheLayerInterface from rxdi/cache like example for global config above
Returns: Instance of CacheLayer class
Optional: settings interface CacheLayerInterface
CacheService.get<any>('layer-name');
Returns: Instance of CacheLayer class
CacheService.remove('layer-name');
Returns: void
CacheLayer.createCacheParams({key: 'endpoint-key', params: {exampleParam: 'test'}});
Complete cache for endpoint with 8 rows more code without it :)
const endpointCache = this.cacheService.get('endpoint-cache');
function getUserById(id: number) {
return Observable.create(observer => {
const ENDPOINT = `/user/${id}`;
const PARAMS = {
client_credentials: true,
};
const cacheAddress = CacheLayer.createCacheParams({ key: ENDPOINT, params: PARAMS });
if (endpointCache.get(cacheAddress)) {
return observer.next(endpointCache.get(cacheAddress));
}
// endpointCache.put method like get returns instance of cached item so we can safely return to the observer above
this.http.post(ENDPOINT, PARAMS)
.map(user =>
observer.next(endpointCache.put({ key: cacheAddress, data: user.json() }))
)
.subscribe()
});
}
const cache = CacheService.get<T>('layer-name');
cache.put({ key:'example-key', data: { exampleData:'' } });
cache.get('example-key');
cache.asObservable('example-key');
cache.remove('example-key');
cache.items.asObservable();
fetch inside browser and will cache particular request to collectioncache.fetch<T>('https://api.github.com/repos/rxdi/core/releases');
ngOnInit() {
this.cacheLayer = this.cache.get<Product>(CART_CACHE_LAYER_NAME);
this.cartItems = this.cacheLayer.items;
// CORRECT EXAMPLE(BestWay) you need to unsubscribe when you leave component!
this.subscription = this.cartItems.asObservable()
.subscribe(items => {
// Do something
});
// ANOTHER CORRECT EXAMPLE (this method will subscribe only once and you cannot get new results if there are any new)
this.cartItems.pipe(take(1)).subscribe(collection => {
// Do something with collection here and initialize only once inside component
});
// WRONG EXAMPLE
this.cartItems.subscribe(collection => {
// don't do anything with collection this way or you will lead subscribing many times to the same collection
});
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
"object unsubscribed" name: "ObjectUnsubscribedError" ngDebugContext:DebugContext_ {view: {…}, nodeIndex: 27, nodeDef: {…}, elDef: {…}, elView: {…}}ngErrorLogger:ƒ ()stack:"ObjectUnsubscribedError: object unsubscribed
MIT © Kristian Tachev(Stradivario)
FAQs

The npm package @rxdi/cache receives a total of 1 weekly downloads. As such, @rxdi/cache popularity was classified as not popular.
We found that @rxdi/cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.