未提供项目说明

cache-guiosoft的Python项目详细描述


缓存GUIOSOFT

使用文件、Redis或本地SQLite缓存数据

codecovCodecov push

[codecov]

Upload Python Package

用于缓存的本地文件

fromcache_gsimportCacheGS# Storage on local directoryfile_cache=CacheGS('path://directory_for_cache_storage')# Storage on local SQLite databaseslite_cache=CacheGS('sqlite://directory_or_file_for_storage')# Storage on Redisredis_cache=CacheGS('redis://host:6379')[Moreoptionsforredis](#Redis options and example)

使用

与INI文件一样,数据按节/键名称分组。在

安装

^{pr2}$

写入值

cache.set_value(section,key,value,ttl:int=0)# ttl is the life time of value in seconds from the time is created

读数

value=cache.get_value(section,key,default=None)

删除值

cache.delete_value(section,key)

清除过期数据

  • Redis缓存中,这由服务器自动处理。在
  • SQLite缓存上,每次实例化都会执行清除。在
  • Local File缓存中,清除每天自动执行一次,每次实例化时都要检查。在

强制清除过期数据

cache.purge_expired()

Redis选项和示例

Redis连接使用Andy McCurdy的redis-py component。 您可以使用与Redis类相同的连接字符串:

  • redis://[[用户名]:[密码]]@本地主机:6379/0在

  • redis://[[用户名]:[密码]]@本地主机:6379/0在

  • unix://[[用户名]:[密码]@/path/to/插座,袜子?分贝=0

      Three URL schemes are supported:
    
      - ```redis://``
        <http://www.iana.org/assignments/uri-schemes/prov/redis>`_ creates a
        normal TCP socket connection
      - ```rediss://``
        <http://www.iana.org/assignments/uri-schemes/prov/rediss>`_ creates a
        SSL wrapped TCP socket connection
      - ``unix://`` creates a Unix Domain Socket connection
    
      There are several ways to specify a database number. The parse function
      will return the first specified option:
          1. A ``db`` querystring option, e.g. redis://localhost?db=0
          2. If using the redis:// scheme, the path argument of the url, e.g.
             redis://localhost/0
          3. The ``db`` argument to this function.
    
      If none of these options are specified, db=0 is used.
    

docker上的Redis

码头工人-合成.yaml在

redis:container_name:'redis'image:'redis:4-alpine'command:redis-server --requirepass 1234ports:-'6379:6379'

要进行测试,只需运行:

docker-compose up

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Jsonify使用Jackson来定义嵌套对象   在Swing中禁用java图形调试   java Selenium Webdriver拖放在Jenkins上不起作用   java我对一个显示器的问题有一个非常不切实际的询问   java增强的“for”循环导致ArrayIndexOutOfBoundsException   ArrayAdapter适用于Java中的安卓编程,字符串数组   linux在Ubuntu上通过PulseAudio播放Java音频文件时出错   java在Spring应用程序中加载内部(类路径)和外部属性文件   java使用Maven连接到mySQL   Java应用程序的设计   websocket在电报api java中与dc的连接   java XMLStreamException,因为xml中的(&N)   java从控制台输出到JTextArea   Java导出文本文件   java实现parseInt方法   java为什么servlet容器会同步对特定资源/servlet的多个请求的访问?   循环中的Java“while”变量   用Java编程一个国际象棋游戏,gameOver布尔不起作用   java如何获得真正的JPanel大小?