Skip to main content

A file storage management package supporting various providers like S3, OSS, and Qiniu.

Project description

efcCache

efcCache 是一个通用的缓存类库,支持多种存储后端,包括:

  • 本地文件
  • SQLite
  • MySQL
  • PostgreSQL
  • Redis

安装

使用 pip 安装 efcCache:

pip install efcCache

快速开始

以下是一个使用 efcCache 的简单示例:

import efcCache
from efcCache.providers.FileCache import FileCache

# 创建缓存管理器
manager = efcCache.CacheManager(default_storage="local")

# 设置存储后端
manager.set_storage("local", FileCache(storage_path="./storage/"))

# 测试文件缓存
print("测试文件缓存:")
manager.get_storage("local").set("test", "文件缓存测试")
print(manager.get_storage("local").get("test"))
print(manager.get_storage("local").exists("test"))
manager.get_storage("local").delete("test")
print(manager.get_storage("local").exists("test"))

引入其他缓存器

import efcCache
from efcCache.providers.FileCache import FileCache
from efcCache.providers.SQLiteCache import SQLiteCache
from efcCache.providers.RedisCache import RedisCache
from efcCache.providers.MySQLCache import MySQLCache
from efcCache.providers.PostgreSQLCache import PostgreSQLCache

# 创建缓存管理器
manager = efcCache.CacheManager(default_storage="local")

# 设置存储后端
manager.set_storage("local", FileCache(storage_path="./storage/"))
manager.set_storage("sqlite", SQLiteCache(storage_path="./storage/cache.db"))
manager.set_storage("redis", RedisCache(host="localhost", port=6379, db=0))
manager.set_storage("mysql", MySQLCache(connection_string="mysql://root:password@localhost:3306/test", table="cache"))
manager.set_storage("postgresql", PostgreSQLCache(connection_string="postgresql://postgres:password@localhost:5432/test", table="cache"))

# 测试文件缓存
print("测试文件缓存:")
manager.get_storage("local").set("test", "文件缓存测试")
print(manager.get_storage("local").get("test"))
print(manager.get_storage("local").exists("test"))
manager.get_storage("local").delete("test")
print(manager.get_storage("local").exists("test"))

# 测试SQLite缓存
print("\n测试SQLite缓存:")
manager.get_storage("sqlite").set("test", "SQLite缓存测试")
print(manager.get_storage("sqlite").get("test"))
print(manager.get_storage("sqlite").exists("test"))
manager.get_storage("sqlite").delete("test")
print(manager.get_storage("sqlite").exists("test"))

# 测试Redis缓存
print("\n测试Redis缓存:")
manager.get_storage("redis").set("test", "Redis缓存测试")
print(manager.get_storage("redis").get("test"))
print(manager.get_storage("redis").exists("test"))
manager.get_storage("redis").delete("test")
print(manager.get_storage("redis").exists("test"))

# 测试MySQL缓存
print("\n测试MySQL缓存:")
manager.get_storage("mysql").set("test", "MySQL缓存测试")
print(manager.get_storage("mysql").get("test"))
print(manager.get_storage("mysql").exists("test"))
manager.get_storage("mysql").delete("test")
print(manager.get_storage("mysql").exists("test"))

# 测试PostgreSQL缓存
print("\n测试PostgreSQL缓存:")
manager.get_storage("postgresql").set("test", "PostgreSQL缓存测试")
print(manager.get_storage("postgresql").get("test"))
print(manager.get_storage("postgresql").exists("test"))
manager.get_storage("postgresql").delete("test")
print(manager.get_storage("postgresql").exists("test"))

# 测试过期时间
print("\n测试过期时间:")
manager.get_storage("local").set("expire_test", "过期测试", expire=5)
print(manager.get_storage("local").get("expire_test"))
import time
print("等待6秒...")
time.sleep(6)
print(manager.get_storage("local").get("expire_test"))

# 测试默认存储
print("\n测试默认存储:")
manager.set("default_test", "默认存储测试")
print(manager.get("default_test"))
print(manager.exists("default_test"))
manager.delete("default_test")
print(manager.exists("default_test"))

贡献

欢迎贡献代码、报告问题或提出改进建议。请查看我们的贡献指南了解更多信息。

许可证

efcCache 使用 MIT 许可证。详情请见 LICENSE 文件。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

efccache-0.0.3.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

efcCache-0.0.3-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file efccache-0.0.3.tar.gz.

File metadata

  • Download URL: efccache-0.0.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for efccache-0.0.3.tar.gz
Algorithm Hash digest
SHA256 4fc35cfde364958a0ea53107fb62a996b6bc97f57be795c9c85ecdd63a56e6d7
MD5 d6715c13087ea0d7b5bf7ee49be4a86b
BLAKE2b-256 25025ec12f9ece1ae0de8a09387d343c6dd60f31657d7ed5e16703d7e3972d1a

See more details on using hashes here.

File details

Details for the file efcCache-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: efcCache-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for efcCache-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8c1c4888215252fabf47089aa86f40a3e4d3c418c766b77335cbe7afdf8c93b2
MD5 bc5f1b5181aa59255c473b7db460e8ed
BLAKE2b-256 281b71a3c30e834e31411e7fa39d7f14ce3940011c48874a993ebc33030e11d4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page