{"id":20186035,"url":"https://github.com/neosmart/sqlitecache","last_synced_at":"2025-04-06T03:11:39.035Z","repository":{"id":42426286,"uuid":"192971761","full_name":"neosmart/SqliteCache","owner":"neosmart","description":"An ASP.NET Core IDistributedCache provider backed by SQLite","archived":false,"fork":false,"pushed_at":"2025-02-19T23:29:17.000Z","size":98,"stargazers_count":98,"open_issues_count":4,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-30T02:09:02.166Z","etag":null,"topics":["aspnetcore","cache","idistributedcache","netcore","nuget","sqlite"],"latest_commit_sha":null,"homepage":"https://neosmart.net/blog/2019/sqlite-cache-for-asp-net-core/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neosmart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-20T18:50:23.000Z","updated_at":"2025-03-22T15:14:54.000Z","dependencies_parsed_at":"2025-01-06T04:11:21.674Z","dependency_job_id":"a3f809a3-44e9-4ab3-bb84-2cae45c24e82","html_url":"https://github.com/neosmart/SqliteCache","commit_stats":null,"previous_names":["neosmart/aspsqlitecache"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neosmart%2FSqliteCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neosmart%2FSqliteCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neosmart%2FSqliteCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neosmart%2FSqliteCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neosmart","download_url":"https://codeload.github.com/neosmart/SqliteCache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427012,"owners_count":20937213,"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":["aspnetcore","cache","idistributedcache","netcore","nuget","sqlite"],"created_at":"2024-11-14T03:15:44.707Z","updated_at":"2025-04-06T03:11:39.006Z","avatar_url":"https://github.com/neosmart.png","language":"C#","readme":"# SqliteCache for ASP.NET Core\n\n[SqliteCache](https://neosmart.net/blog/sqlite-cache-for-asp-net-core) is a persistent cache\nimplementing `IDistributedCache` for .NET and ASP.NET Core projects.\n\nSqliteCache uses a locally stored SQLite database file (taking advantage of SQLite's battle-tested\nsafe multi-threaded access features) to replicate persistent caching, allowing developers to mimic\nthe behavior of staging or production targets without all the overhead or hassle of a traditional\n`IDistributedCache` implementation. You can read more about its design and inspiration in [the\nofficial release post](https://neosmart.net/blog/sqlite-cache-for-asp-net-core) on the NeoSmart\nblog.\n\n## Why `NeoSmart.Caching.Sqlite`?\n\nThe currently available options for caching in ASP.NET Core projects are either all ephemeral\nin-memory cache offerings (`IMemoryCache` and co.) -- aka non-persistent -- or else have a whole\nslew of dependencies and requirements that require at the very least administrator privileges and\nbackground services hogging up system resources and needing updates and maintenance to requiring\nmultiple machines and a persistent network configuration.\n\n* `NeoSmart.Caching.Sqlite` has no dependencies on background services that hog system resources and\nneed to be updated or maintained (*cough* *cough* NCache *cough* *cough*)\n* `NeoSmart.Caching.Sqlite` is fully cross-platform and runs the same on your Windows PC or your\ncolleagues' Linux, FreeBSD, and macOS workstations (unlike, say, Redis)\n* `NeoSmart.Caching.Sqlite` doesn't need administrator privileges to install - or even any installation\nfor that matter (SQL Express LocalDB, this one is aimed at you)\n* `NeoSmart.Caching.Sqlite` is a fully contained `IDistributedCache` offering that is installed and\nupdated alongside the rest of your packages via NuGet, Paket, or whatever other option you're\nalready using to manage your dependencies.\n\n## Installation\n\nSqliteCache is available via the NuGet, and can be installed in the Package Manager Console as\nfollows:\n\n```\nInstall-Package NeoSmart.Caching.Sqlite\n```\n\n**If using this in an ASP.NET Core project**, you can install `NeoSmart.Caching.Sqlite.AspNetCore` (also\nor instead) to get a convenient helper method for dependency injection (used below):\n\n```\nInstall-Package NeoSmart.Caching.Sqlite.AspNetCore\n```\n\nNote: If you install `NeoSmart.Caching.Sqlite.AspNetCore` you do not need to manually install\n`NeoSmart.Caching.Sqlite`, as it it will be installed automatically/transitively.\n\n## Usage\n\nUsing SqliteCache is straight-forward, and should be extremely familiar for anyone that's configured\nan ASP.NET Core application before. *Starting by adding a namespace import `using\nNeoSmart.Caching.Sqlite` makes things easier as the editor will pull in the correct extension\nmethods.*\n\nIf using SqliteCache in an ASP.NET Core project, the SQLite-backed cache should be added as an\n`IDistributedCache` type by adding the following to your `ConfigureServices` method, by default\nlocated in `Startup.cs`, after using the correct namespace `NeoSmart.Caching.Sqlite`:\n\n```csharp\n// using NeoSmart.Caching.Sqlite;\n\npublic void ConfigureServices(IServiceCollection services)\n{\n    ...\n\n    // Note: this *must* come before services.AddMvc() and/or services.AddRazorPages()!\n    services.AddSqliteCache(options =\u003e {\n        options.CachePath = @\"C:\\data\\bazaar\\cache.db\";\n    });\n\n    services.AddMvc();\n\n    ...\n}\n```\n\nAfterwards, the `SqliteCache` instance will be made available to both the framework and the\napplication via dependency injection, and can be imported and used via either the\n`IDistributedCache` abstract type or the concrete `SqliteCache` type:\n\n```csharp\n// using Microsoft.Extensions.Caching.Distributed;\npublic class FooModel(DbContext db, IDistributedCache cache)\n{\n    _db = db;\n    _cache = cache;\n\n    cache.SetString(\"foo\", \"bar\");\n    Assert.AreEqual(cache.GetString(\"foo\"), \"bar\");\n\n    Assert.AreEqual(typeof(NeoSmart.Caching.Sqlite.SqliteCache),\n                    cache.GetType());\n}\n```\n\nTo take advantage of SqliteCache-specific features or functionality that aren't exposed via the\n`IDistributedCache` façade, you'll need to inject `SqliteCache` into your classes/methods rather than\n`IDistributedCache`. For example, to globally clear the cache after performing some operation:\n\n```csharp\n// using NeoSmart.Caching.Sqlite;\npublic class BarModel(DbContext db, SqliteCache cache)\n{\n    _db = db;\n    _cache = cache;\n}\n\npublic ActionResult OnPostAsync()\n{\n    ...\n    await _db.SomethingDestructiveAsync();\n\n    // We need to invalidate all the cache, since it's too hard to\n    // account for the changes this operation caused for legacy reasons.\n    await _cache.ClearAsync();\n\n    ...\n}\n```\n\n## License\n\nSqliteCache is developed and maintained by Mahmoud Al-Qudsi of NeoSmart Technologies. The project is\nprovided free to the community under the terms of the MIT open source license.\n\n## Contributing\n\nWe are open to pull requests and contributions aimed at the code, documentation, unit tests, or\nanything else. If you're mulling an extensive contribution, file an issue first to make sure we're\nall on the same page, otherwise, PR away!\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneosmart%2Fsqlitecache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneosmart%2Fsqlitecache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneosmart%2Fsqlitecache/lists"}