{"id":13599352,"url":"https://github.com/IISResetMe/PSCache","last_synced_at":"2025-04-10T12:32:22.799Z","repository":{"id":54540582,"uuid":"104669651","full_name":"IISResetMe/PSCache","owner":"IISResetMe","description":"Generic PowerShell cache implementation","archived":false,"fork":false,"pushed_at":"2021-02-11T21:56:14.000Z","size":42,"stargazers_count":51,"open_issues_count":3,"forks_count":1,"subscribers_count":7,"default_branch":"development","last_synced_at":"2024-11-07T00:41:54.083Z","etag":null,"topics":["caching","powershell"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IISResetMe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-24T19:15:57.000Z","updated_at":"2024-04-26T03:38:21.000Z","dependencies_parsed_at":"2022-08-13T19:10:19.486Z","dependency_job_id":null,"html_url":"https://github.com/IISResetMe/PSCache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IISResetMe%2FPSCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IISResetMe%2FPSCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IISResetMe%2FPSCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IISResetMe%2FPSCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IISResetMe","download_url":"https://codeload.github.com/IISResetMe/PSCache/tar.gz/refs/heads/development","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248217145,"owners_count":21066633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["caching","powershell"],"created_at":"2024-08-01T17:01:02.691Z","updated_at":"2025-04-10T12:32:17.788Z","avatar_url":"https://github.com/IISResetMe.png","language":"PowerShell","funding_links":[],"categories":["PowerShell"],"sub_categories":[],"readme":"# PSCache\nGeneric PowerShell cache implementation\n\n----\n\n## What is PSCache?\n\nPSCache grew out of a need to abstract away a hashtable-based \"caching\" scheme that I personally found myself implementing over and over again. PSCache transparently caches the results from previous queries using a custom `fetcher` - a scriptblock that'll retrieve a value from elsewhere based on a single parameter.\n\nHere's a simple example using `PSCache` as a transparent store for results returned from `Get-ADUser`:\n\n```powershell\nImport-Module PSCache\n$ADUserCache = New-PSCache -Fetcher { Get-ADUser $_ -Properties manager,title,employeeId }\n\n# Fetch the user \"jdoe\" - this first cache-miss will cauce PSCache to call the `$Fetcher` scriptblock once and return the result\n$ADUserCache.Get('jdoe')\n\n# Fetch the user \"jdoe\" again - this time he'll be returned directly from the cache\n$ADUserCache.Get('jdoe')\n```\n\n## Which eviction policies are supported?\n\nPSCache version 0.1.1 comes with 3 optional eviction policy implementations:\n\n### Least Recently Used (LRU)\n\nSimple LRU policy which evicts the least recently cached entry\n```powershell\n# Create a cache for URL page titles\n$PageTitleCache = New-PSCache { param($url) (Invoke-WebRequest $url).title } -EvictionPolicy LRU -Capacity 3\n\n# Grab a few url page titles\n$PageTitleCache.Get('https://google.com')          # cache miss, cache count = 1\n$PageTitleCache.Get('https://github.com')          # cache miss, cache count = 2\n$PageTitleCache.Get('https://google.com')          # cache hit\n$PageTitleCache.Get('https://stackoverflow.com')   # cache miss, cache count = 3\n$PageTitleCache.Get('https://bing.com')            # cache miss, cache count = 3, 'https://github.com' evicted\n$PageTitleCache.Get('https://github.com')          # cache miss, cache count = 3, 'https://google.com' evicted\n$PageTitleCache.Get('https://google.com')          # cache miss, cache count = 3, 'https://stackoverflow.com' evicted\n```\n\n### Most Recently Used (MRU)\n\nSimple MRU policy which evicts the most recently cached entry\n```powershell\n# Create a cache for URL page titles\n$PageTitleCache = New-PSCache { param($url) (Invoke-WebRequest $url).title } -EvictionPolicy MRU -Capacity 3\n\n# Grab a few url page titles\n$PageTitleCache.Get('https://google.com')          # cache miss, cache count = 1\n$PageTitleCache.Get('https://github.com')          # cache miss, cache count = 2\n$PageTitleCache.Get('https://google.com')          # cache hit\n$PageTitleCache.Get('https://stackoverflow.com')   # cache miss, cache count = 3\n$PageTitleCache.Get('https://bing.com')            # cache miss, cache count = 3, 'https://stackoverflow.com' evicted\n$PageTitleCache.Get('https://github.com')          # cache hit\n$PageTitleCache.Get('https://google.com')          # cache hit\n```\n\n### Least Frequently Used (LFU)\n\nSimple LFU policy which evicts the least recently cached entry of those least frequently used\n```powershell\n# Create a cache for URL page titles\n$PageTitleCache = New-PSCache { param($url) (Invoke-WebRequest $url).title } -EvictionPolicy LFU -Capacity 3\n\n# Grab a few url page titles\n$PageTitleCache.Get('https://google.com')          # cache miss, cache count = 1\n$PageTitleCache.Get('https://github.com')          # cache miss, cache count = 2\n$PageTitleCache.Get('https://google.com')          # cache hit\n$PageTitleCache.Get('https://stackoverflow.com')   # cache miss, cache count = 3\n$PageTitleCache.Get('https://bing.com')            # cache miss, cache count = 3, 'https://stackoverflow.com' evicted\n$PageTitleCache.Get('https://github.com')          # cache miss, cache count = 3, 'https://bing.com' evicted\n$PageTitleCache.Get('https://google.com')          # cache hit\n```\n\n## Roadmap\n\nPSCache is currently very basic. Future plans include both time- and counter-based eviction policies (globally and per-key), as well as explicit cache size settings.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIISResetMe%2FPSCache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FIISResetMe%2FPSCache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIISResetMe%2FPSCache/lists"}