框架开发(六)----缓存类

一 理论补充

  缓存是临时开辟出来的一块存放数据的区域, 这样在下一次取数据的时候就可以直接去取了.

  因为内存的材质相对于硬盘的读写明显优越性,而且SDRAM等的性价比高,缓存最好保存在内存里.PHP中的缓存主要分两种,逻辑代码层面的缓存和数据层面的缓存.逻辑缓存主要是编译缓存,php 是脚本解析形式的语言,即php 是不转换为机器码的,php在服务器cgi 分配给进程,fastcgi是常住内存的进程,fpm管理cgi的进程调度,有几种IO模式例如Epoll,worker 等.php代码首先被编译成zend 虚拟机的opcode 二进制码,然后被zvm执行,opcode 是进程创建在内存中的,进程之间不共享,为共享需要专门开辟出一个空间,是用专门的程序管理,如APC||xcache||zend optimizer等;数据缓存比较多而且常见,如redis,memcache,ob,smarty等对php的结果进行缓存.

二 缓存选用

  因为领导点名要用memcache 所以先写一个memcache 的.

  1. 安装. Centos6.3 安装memcache,编译安装.  

https://github.com/memcached/memcached/wiki/ReleaseNotes1425

wget || tar zxvf || ./configure --prefix=/src/memcache  --with-libevent=/src/libevent/

***所以需要先安装libevent ,libevent 是一个事件通知机制的类,被用于多种模式下,包括epool|| pool || select 等多种IO机制下.  

http://libevent.org/ 下载, tar zxvf || cd || ./configure --prefix=/src/libevent/  make &&make (test) install && make clean

安装完毕.启动/src/memcache -d -m 1024 -u root  // 启动memcache

*** memcache是一个项目,memcached 是程序文件.存的是hashtable ,用的是LRU,缓存算法很多种,有兴趣的自己看

 1 memcached 1.4.25
 2 -p <num>      TCP port number to listen on (default: 11211)  //tcp端口号
 3 -U <num>      UDP port number to listen on (default: 11211, 0 is off) //udp 端口号
 4 -s <file>     UNIX socket path to listen on (disables network support) //socket 连接,类似于mysql.sock
 5 -A            enable ascii "shutdown" command
 6 -a <mask>     access mask for UNIX socket, in octal (default: 0700)
 7 -l <addr>     interface to listen on (default: INADDR_ANY, all addresses)   //监听端口
 8               <addr> may be specified as host:port. If you don‘t specify
 9               a port number, the value you specified with -p or -U is
10               used. You may specify multiple addresses separated by comma
11               or by using -l multiple times
12 -d            run as a daemon //作为一个守护进程
13 -r            maximize core file limit
14 -u <username> assume identity of <username> (only when run as root)
15 -m <num>      max memory to use for items in megabytes (default: 64 MB)
16 -M            return error on memory exhausted (rather than removing items)
17 -c <num>      max simultaneous connections (default: 1024)
18 -k            lock down all paged memory.  Note that there is a
19               limit on how much memory you may lock.  Trying to
20               allocate more than that would fail, so be sure you
21               set the limit correctly for the user you started
22               the daemon with (not for -u <username> user;
23               under sh this is done with ‘ulimit -S -l NUM_KB‘).
24 -v            verbose (print errors/warnings while in event loop)
25 -vv           very verbose (also print client commands/reponses)
26 -vvv          extremely verbose (also print internal state transitions)
27 -h            print this help and exit
28 -i            print memcached and libevent license
29 -V            print version and exit
30 -P <file>     save PID in <file>, only used with -d option
31 -f <factor>   chunk size growth factor (default: 1.25)
32 -n <bytes>    minimum space allocated for key+value+flags (default: 48)
33 -L            Try to use large memory pages (if available). Increasing
34               the memory page size could reduce the number of TLB misses
35               and improve the performance. In order to get large pages
36               from the OS, memcached will allocate the total item-cache
37               in one large chunk.
38 -D <char>     Use <char> as the delimiter between key prefixes and IDs.
39               This is used for per-prefix stats reporting. The default is
40               ":" (colon). If this option is specified, stats collection
41               is turned on automatically; if not, then it may be turned on
42               by sending the "stats detail on" command to the server.
43 -t <num>      number of threads to use (default: 4)
44 -R            Maximum number of requests per event, limits the number of
45               requests process for a given connection to prevent
46               starvation (default: 20)
47 -C            Disable use of CAS
48 -b <num>      Set the backlog queue limit (default: 1024)
49 -B            Binding protocol - one of ascii, binary, or auto (default)
50 -I            Override the size of each slab page. Adjusts max item size
51               (default: 1mb, min: 1k, max: 128m)
52 -F            Disable flush_all command
53 -o            Comma separated list of extended or experimental options
54               - (EXPERIMENTAL) maxconns_fast: immediately close new
55                 connections if over maxconns limit
56               - hashpower: An integer multiplier for how large the hash
57                 table should be. Can be grown at runtime if not big enough.
58                 Set this based on "STAT hash_power_level" before a
59                 restart.
60               - tail_repair_time: Time in seconds that indicates how long to wait before
61                 forcefully taking over the LRU tail item whose refcount has leaked.
62                 Disabled by default; dangerous option.
63               - hash_algorithm: The hash table algorithm
64                 default is jenkins hash. options: jenkins, murmur3
65               - lru_crawler: Enable LRU Crawler background thread
66               - lru_crawler_sleep: Microseconds to sleep between items
67                 default is 100.
68               - lru_crawler_tocrawl: Max items to crawl per slab per run
69                 default is 0 (unlimited)
70               - lru_maintainer: Enable new LRU system + background thread
71               - hot_lru_pct: Pct of slab memory to reserve for hot lru.
72                 (requires lru_maintainer)
73               - warm_lru_pct: Pct of slab memory to reserve for warm lru.
74                 (requires lru_maintainer)
75               - expirezero_does_not_evict: Items set to not expire, will not evict.
76                 (requires lru_maintainer)

启动 memcache  memcache -d -uroot

*** 没有acl ,可以用-l 指定listen地址,也可以用iptables,没有认证机制,没有写文件机制,这些自己可以源码,分布式用代码来保证。

三  试用

  万能的telnet ,win7/8/10在control,安装telnet,xp自带,unix yum install

  telnet 127.0.0.1 11211 本人用的nat模式虚拟机,所以还得配个pat,可以用ssh,也可在vminter网关配.竟然没效果,试下80

80 有用,开个11211 等下

OK了,回显还是有问题,不影响验证功能. *** 启动memcache时候没有配listen 127.0.0.1 是为了这里的pat

stats 看下

四  基本命令

  set ||add ||replace || delete || stats || flush || get

  

时间: 2024-08-24 20:28:25

框架开发(六)----缓存类的相关文章

框架开发(五)----自动加载类

一 . 为什么自动加载 自动加载字面的意思就不解释了.我这里自动加载类解析下 是自动加载类文件的意思.__autoload方法完全可行,但是不要问为什么,还是用spl_autoload_register.不只是灵活,而且就是灵活,还是灵活,体现在__autoload只能这么命名,spl_auto_register() 能调用不同的函数. 二  自动加载函数原理   通常情况下,一个类的定义都是一个文件,当类与类需要相互引用的时候,就需要include(require)相应的类文件,带来的问题就是

UI(UGUI)框架(二)-------------UIManager单例模式与开发BasePanel面板基类/UIManage统一管理UI面板的实例化/开发字典扩展类

UIManage单实例: 1 /// 单例模式的核心 2 /// 1,定义一个静态的对象 在外界访问 在内部构造 3 /// 2,构造方法私有化 4 5 private static UIManager _instance; 6 7 public static UIManager Instance 8 { 9 get 10 { 11 if (_instance == null) 12 { 13 _instance = new UIManager(); 14 } 15 return _instan

【cocos2d-x游戏开发】cocos中的三种缓存类

Cocos中有三种缓存类: (1):纹理缓存:TextureCache (2):精灵帧缓存:SpriteFrameCache (3):动画缓存:AnimationCache 游戏最要重要的就是流畅度,如果我们的游戏经常因为加载资源出现卡顿的情况,那么这个游戏就没有很好地游戏体验.所以,为了解决这个问题,缓存就应运而生了. 缓存的目的就是:现将所需资源加载到内存中,之后再次使用该资源的时候,就可以直接从内存中读出,而不需要重新加载,从而减少了CPU和GPU的内存占用. TextureCache 在

【FastDev4Android框架开发】RecyclerView完全解析之下拉刷新与上拉加载SwipeRefreshLayout(三十一)

转载请标明出处: http://blog.csdn.net/developer_jiangqq/article/details/49992269 本文出自:[江清清的博客] (一).前言: [好消息]个人网站已经上线运行,后面博客以及技术干货等精彩文章会同步更新,请大家关注收藏:http://www.lcode.org 话说RecyclerView已经面市很久,也在很多应用中得到广泛的使用,在整个开发者圈子里面也拥有很不错的口碑,那说明RecyclerView拥有比ListView,GridVi

开源|ns4_frame分布式服务框架开发指南

导语:宜信于2019年3月29日正式开源nextsystem4(以下简称"NS4")系列模块.此次开源的NS4系列模块是围绕当前支付系统笨重.代码耦合度高.维护成本高而产生的分布式业务系统解决方案.NS4系列框架允许创建复杂的流程/业务流,对于业务服务节点的实现可串联,可分布式.其精简.轻量,实现了"脱容器"(不依赖tomcat.jetty等容器)独立运行.NS4系列框架的设计理念是将业务和逻辑进行分离,开发人员只需通过简单的配置和业务实现就可以实现逻辑复杂.性能高

Eclipse+CXF框架开发Web服务实战

一. 说明 采用CXF框架开发webservice. 所用软件及版本如下. ? 操作系统:Window XP SP3. ? JDK:JDK1.6.0_07,http://www.oracle.com/technetwork/java/javase/downloads/index.html. ? Tomcat:apache-tomcat-6.0.14.exe,http://tomcat.apache.org/. ? IDE:eclipse-jee-juno-SR1-win32.zip,http:/

Jdon框架开发指南

Jdon框架快速开发指南 开发主要步骤如下: JdonFramework6.0以上两步开发见这里. 快速配置指南 新增/查询/修改/删除(CRUD); 批量查询和分页显示 本文Step By Step详细讲解如何使用Jdon框架基于领域模型快速开发这两个功能,通过Jdon框架的可以快速完成系统原型(ArcheType),使得开发者将真正精力集中在每个项目系统的特殊业务处理. 本案例源码下载 按这里查看更详细全面文档 快速配置指南 Jdon框架有一个配置文件叫jdonframework.xml,其

MapReduce教程(一)基于MapReduce框架开发&lt;转&gt;

1 MapReduce编程 1.1 MapReduce简介 MapReduce是一种编程模型,用于大规模数据集(大于1TB)的并行运算,用于解决海量数据的计算问题. MapReduce分成了两个部分: 1.映射(Mapping)对集合里的每个目标应用同一个操作.即,如果你想把表单里每个单元格乘以二,那么把这个函数单独地应用在每个单元格上的操作就属于mapping. 2.化简(Reducing)遍历集合中的元素来返回一个综合的结果.即,输出表单里一列数字的和这个任务属于reducing. 你向Ma

【转载】Android应用框架及常用工具类总结

转载自:Android应用框架 http://www.tuicool.com/articles/feqmQj 常用工具类总结    http://blog.csdn.net/krislight/article/details/11354119 一. UML类图复习: UML类图中有些标记很容易混淆,这里先复习下,请大家看下面这幅图: 注:这幅图来自<大话设计模式>这本书中的插图. 二.应用框架: A.基本概念 抽象(抽出共同之现象)——在同领域的程序中,常含有许多类别,这些类别有其共同点,我们