Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
github.com/alexssd7/cache
CDN-like, middleware memory cache for Go applications with integrated shielding and Go 1.18 Generics.
package main
import (
"context"
"fmt"
"time"
"github.com/AlexSSD7/cache"
)
type Person struct {
Name string
Age uint32
}
func fetchPerson(name string) (*Person, error) {
// Heavy task here, like a DB call.
// Shielding makes the fetch functions
// mutually exclusive, to prevent
// unncecessary duplicate calls
// if there is no cache in memory.
// For the purpose of this example though,
// we will just return sample objects.
switch name {
case "John":
return &Person{Name: "John", Age: 27}, nil
case "Steve":
return &Person{Name: "Steve", Age: 32}, nil
default:
return nil, fmt.Errorf("unknown person with name '%v'", name)
}
}
func main() {
// Create a new ShieldedCache instance with 5-second GC interval.
cache := cache.NewShieldedCache[*Person](time.Second * 5)
cacheCtx, cacheCtxCancel := context.WithCancel(context.Background())
defer cacheCtxCancel()
// Worker is a separate goroutine running in background.
// It is responsible for evicting old, expired objects.
cache.StartWorker(cacheCtx)
// If there is "person_john" object in cache, return it. Otherwise, execute fetchPerson("John").
ret, hit, err := cache.Fetch("person_john", time.Minute, func() (*Person, error) {
return fetchPerson("John")
})
fmt.Printf("result: %+v, hit: %v, err: %v\n", ret.Data, hit, err)
// result: &{Name:John Age:27}, hit: false, err: <nil>
ret, hit, err = cache.Fetch("person_john", time.Minute, func() (*Person, error) {
return fetchPerson("John")
})
fmt.Printf("result: %+v, hit: %v, err: %v\n", ret.Data, hit, err)
// result: &{Name:John Age:27}, hit: true, err: <nil>
ret, hit, err = cache.Fetch("person_steve", time.Minute, func() (*Person, error) {
return fetchPerson("Steve")
})
fmt.Printf("result: %+v, hit: %v, err: %v\n", ret.Data, hit, err)
// result: &{Name:Steve Age:32}, hit: false, err: <nil>
ret, hit, err = cache.Fetch("person_alice", time.Minute, func() (*Person, error) {
return fetchPerson("Alice")
})
fmt.Printf("result: %+v, hit: %v, err: %v\n", ret, hit, err)
// result: <nil>, hit: false, err: unknown person with name 'Alice'
}
MIT
FAQs
Unknown package
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.