当前位置:首页>python>Python Web开发:缓存与性能优化

Python Web开发:缓存与性能优化

  • 2026-06-27 16:57:49
Python Web开发:缓存与性能优化
副标题

: 90%的人不知道,合理的缓存能让你的API响应快10倍

痛点:为什么你的API总是响应缓慢?

2025年某项目数据库查询每秒1000次,CPU占用90%。问题出在哪?工程师没有使用缓存。

真相

:缓存是性能优化的第一选择,减少数据库访问能显著提升性能。

缓存类型适用场景命中率
内存缓存热点数据90%+
Redis缓存分布式85%+
CDN缓存静态资源95%+
浏览器缓存前端资源99%+

一、缓存基础

1.1 什么是缓存

缓存是将频繁访问的数据存储在快速存储介质中,减少原始数据源的访问。

请求流程(无缓存):

客户端 → API → 数据库 → 返回结果

(每次都要查数据库)

请求流程(有缓存):

客户端 → API → 缓存命中 → 返回结果

(90%请求直接返回)

1.2 FastAPI缓存中间件

from fastapi import FastAPI, Request

from fastapi.responses import JSONResponse

import time

from functools import wraps

import hashlib

app = FastAPI()

简单内存缓存

cache = {}

CACHE_TTL = 300 # 5分钟

def get_cache_key(path: str, query_params: dict) -> str:

"""生成缓存键"""

key_string = f"{path}:{str(query_params)}"

return hashlib.md5(key_string.encode()).hexdigest()

def is_cache_expired(timestamp: float) -> bool:

"""检查缓存是否过期"""

return time.time() - timestamp > CACHE_TTL

@app.middleware("http")

async def cache_middleware(request: Request, call_next):

"""缓存中间件"""

# 只缓存GET请求

if request.method != "GET":

return await call_next(request)

# 生成缓存键

cache_key = get_cache_key(

request.url.path,

dict(request.query_params)

)

# 检查缓存

if cache_key in cache:

cached_data, timestamp = cache[cache_key]

if not is_cache_expired(timestamp):

return JSONResponse(cached_data)

# 执行请求

response = await call_next(request)

# 缓存响应(只缓存200状态码)

if response.status_code == 200:

body = await response.body()

cache[cache_key] = (

{"status": response.status_code, "body": body.decode()},

time.time()

)

return response

二、Redis缓存

2.1 Redis连接

pip install redis
import redis

import json

from datetime import timedelta

连接Redis

redis_client = redis.Redis(

host="localhost",

port=6379,

db=0,

decode_responses=True

)

连接池(推荐)

pool = redis.ConnectionPool(

host="localhost",

port=6379,

db=0,

max_connections=20,

decode_responses=True

)

redis_client = redis.Redis(connection_pool=pool)

2.2 基础缓存操作

from typing import Any, Optional

class Cache:

"""缓存工具类"""

@staticmethod

def get(key: str) -> Optional[Any]:

"""获取缓存"""

value = redis_client.get(key)

if value is None:

return None

try:

return json.loads(value)

except json.JSONDecodeError:

return value

@staticmethod

def set(key: str, value: Any, expire: int = 300) -> bool:

"""设置缓存"""

try:

redis_client.setex(

key,

timedelta(seconds=expire),

json.dumps(value)

)

return True

except Exception as e:

print(f"缓存设置失败: {e}")

return False

@staticmethod

def delete(key: str) -> bool:

"""删除缓存"""

return bool(redis_client.delete(key))

@staticmethod

def exists(key: str) -> bool:

"""检查缓存是否存在"""

return bool(redis_client.exists(key))

@staticmethod

def increment(key: str, amount: int = 1) -> int:

"""递增"""

return redis_client.incr(key, amount)

@staticmethod

def expire(key: str, seconds: int) -> bool:

"""设置过期时间"""

return bool(redis_client.expire(key, seconds))

使用

Cache.set("user:1", {"id": 1, "name": "Alice"}, expire=3600)

user = Cache.get("user:1")

Cache.delete("user:1")

2.3 FastAPI集成

from fastapi import FastAPI, Depends

from pydantic import BaseModel

from typing import Optional

app = FastAPI()

class User(BaseModel):

id: int

name: str

email: str

模拟数据库

users_db = {

1: User(id=1, name="Alice", email="alice@example.com"),

2: User(id=2, name="Bob", email="bob@example.com"),

}

def get_user_from_db(user_id: int) -> Optional[User]:

"""从数据库获取用户"""

return users_db.get(user_id)

@app.get("/users/{user_id}", response_model=User)

async def get_user(user_id: int):

"""获取用户(带缓存)"""

cache_key = f"user:{user_id}"

# 尝试从缓存获取

cached_user = Cache.get(cache_key)

if cached_user:

return cached_user

# 从数据库获取

user = get_user_from_db(user_id)

if not user:

raise HTTPException(status_code=404, detail="用户不存在")

# 写入缓存

Cache.set(cache_key, user.model_dump(), expire=300)

return user

三、缓存策略

3.1 缓存穿透

# 问题:查询不存在的数据,缓存和数据库都没有

解决:缓存空值

@app.get("/users/{user_id}", response_model=User)

async def get_user_safe(user_id: int):

"""安全获取用户(防穿透)"""

cache_key = f"user:{user_id}"

# 尝试从缓存获取

cached_user = Cache.get(cache_key)

# 空值标记(防止穿透)

if cached_user == "__NOT_FOUND__":

raise HTTPException(status_code=404, detail="用户不存在")

if cached_user:

return cached_user

# 从数据库获取

user = get_user_from_db(user_id)

if not user:

# 缓存空值(设置短过期时间)

Cache.set(cache_key, "__NOT_FOUND__", expire=60)

raise HTTPException(status_code=404, detail="用户不存在")

# 写入缓存

Cache.set(cache_key, user.model_dump(), expire=300)

return user

3.2 缓存击穿

import asyncio

from functools import wraps

async_locks = {}

async def get_user_with_lock(user_id: int) -> User:

"""带锁获取用户(防击穿)"""

cache_key = f"user:{user_id}"

# 尝试从缓存获取

cached_user = Cache.get(cache_key)

if cached_user and cached_user != "__NOT_FOUND__":

return cached_user

# 获取锁

lock_key = f"lock:user:{user_id}"

# 尝试获取锁

acquired = redis_client.set(lock_key, "1", nx=True, ex=10)

if not acquired:

# 等待锁释放后重试

await asyncio.sleep(0.1)

return await get_user_with_lock(user_id)

try:

# 双重检查缓存

cached_user = Cache.get(cache_key)

if cached_user and cached_user != "__NOT_FOUND__":

return cached_user

# 从数据库获取

user = get_user_from_db(user_id)

if not user:

Cache.set(cache_key, "__NOT_FOUND__", expire=60)

raise HTTPException(status_code=404, detail="用户不存在")

# 写入缓存

Cache.set(cache_key, user.model_dump(), expire=300)

return user

finally:

# 释放锁

redis_client.delete(lock_key)

3.3 缓存雪崩

import random

def get_user_with_random_expire(user_id: int) -> User:

"""带随机过期时间(防雪崩)"""

cache_key = f"user:{user_id}"

# 随机过期时间(基础时间 ± 随机偏移)

base_expire = 300

random_offset = random.randint(-60, 60)

expire = max(60, base_expire + random_offset)

cached_user = Cache.get(cache_key)

if cached_user and cached_user != "__NOT_FOUND__":

return cached_user

user = get_user_from_db(user_id)

if not user:

Cache.set(cache_key, "__NOT_FOUND__", expire=60)

raise HTTPException(status_code=404, detail="用户不存在")

# 写入缓存(随机过期时间)

Cache.set(cache_key, user.model_dump(), expire=expire)

return user

四、装饰器缓存

4.1 函数缓存装饰器

from functools import wraps

import hashlib

import inspect

def cache_result(expire: int = 300, prefix: str = "func"):

"""函数结果缓存装饰器"""

def decorator(func):

@wraps(func)

async def wrapper(args, *kwargs):

# 生成缓存键

sig = inspect.signature(func)

bound = sig.bind(args, *kwargs)

bound.apply_defaults()

key_parts = [prefix, func.__name__]

for name, value in bound.arguments.items():

if isinstance(value, (str, int, float, bool)):

key_parts.append(f"{name}={value}")

cache_key = ":".join(key_parts)

# 尝试从缓存获取

cached = Cache.get(cache_key)

if cached is not None:

return cached

# 执行函数

result = await func(args, *kwargs)

# 写入缓存

Cache.set(cache_key, result, expire=expire)

return result

return wrapper

return decorator

使用

@cache_result(expire=600, prefix="user")

async def get_user_data(user_id: int):

"""获取用户数据(带缓存)"""

# 模拟耗时操作

await asyncio.sleep(1)

return {"id": user_id, "name": "Alice"}

@app.get("/users/{user_id}/data")

async def get_user_data_endpoint(user_id: int):

return await get_user_data(user_id)

4.2 类方法缓存

def cache_method(expire: int = 300):

"""类方法缓存装饰器"""

def decorator(func):

@wraps(func)

async def wrapper(self, args, *kwargs):

cache_key = f"{self.__class__.__name__}:{func.__name__}:{args}:{kwargs}"

cached = Cache.get(cache_key)

if cached is not None:

return cached

result = await func(self, args, *kwargs)

Cache.set(cache_key, result, expire=expire)

return result

return wrapper

return decorator

class UserService:

@cache_method(expire=300)

async def get_user_profile(self, user_id: int):

return {"id": user_id, "profile": "data"}

五、HTTP缓存

5.1 响应缓存头

from fastapi import Response

from datetime import datetime, timedelta

@app.get("/static/{filename}")

async def serve_static(filename: str, response: Response):

"""静态文件(带HTTP缓存)"""

file_path = Path("static") / filename

if not file_path.exists():

raise HTTPException(status_code=404, detail="文件不存在")

# 设置缓存头

response.headers["Cache-Control"] = "public, max-age=31536000" # 1年

response.headers["ETag"] = f'"{file_path.stat().st_mtime}"'

return FileResponse(file_path)

5.2 条件请求

@app.get("/api/data")

async def get_data(request: Request):

"""支持条件请求"""

# 生成ETag

data = {"version": "1.0", "items": [...]}

etag = hashlib.md5(json.dumps(data).encode()).hexdigest()

# 检查If-None-Match

if_none_match = request.headers.get("If-None-Match")

if if_none_match and if_none_match.strip('"') == etag:

return Response(status_code=304)

response = JSONResponse(data)

response.headers["ETag"] = f'"{etag}"'

response.headers["Cache-Control"] = "public, max-age=60"

return response

5.3 Last-Modified

@app.get("/api/config")

async def get_config(request: Request):

"""支持Last-Modified"""

config = {"setting": "value"}

# 获取最后修改时间

last_modified = "Wed, 26 May 2026 12:00:00 GMT"

# 检查If-Modified-Since

if_modified_since = request.headers.get("If-Modified-Since")

if if_modified_since == last_modified:

return Response(status_code=304)

response = JSONResponse(config)

response.headers["Last-Modified"] = last_modified

response.headers["Cache-Control"] = "public, max-age=60"

return response

六、数据库查询缓存

6.1 SQLAlchemy缓存

from sqlalchemy.orm import Session

from typing import Optional, List

def get_user_with_cache(db: Session, user_id: int) -> Optional[User]:

"""带缓存的用户查询"""

cache_key = f"db:user:{user_id}"

# 尝试从缓存获取

cached = Cache.get(cache_key)

if cached:

return User(**cached)

# 从数据库查询

user = db.query(UserModel).filter(UserModel.id == user_id).first()

if not user:

return None

# 写入缓存

Cache.set(cache_key, user.model_dump(), expire=300)

return user

def get_users_with_cache(db: Session, skip: int = 0, limit: int = 100) -> List[User]:

"""带缓存的用户列表查询"""

cache_key = f"db:users:{skip}:{limit}"

cached = Cache.get(cache_key)

if cached:

return [User(**u) for u in cached]

users = db.query(UserModel).offset(skip).limit(limit).all()

if not users:

return []

Cache.set(cache_key, [u.model_dump() for u in users], expire=300)

return [User.model_validate(u) for u in users]

6.2 缓存失效

def invalidate_user_cache(user_id: int):

"""失效用户缓存"""

Cache.delete(f"user:{user_id}")

Cache.delete(f"db:user:{user_id}")

def invalidate_users_list_cache():

"""失效用户列表缓存"""

# 删除所有用户列表缓存

keys = redis_client.keys("db:users:*")

if keys:

redis_client.delete(*keys)

@app.put("/users/{user_id}")

async def update_user(user_id: int, user_in: UserUpdate, db: Session = Depends(get_db)):

"""更新用户(同时失效缓存)"""

user = get_user_with_cache(db, user_id)

if not user:

raise HTTPException(status_code=404, detail="用户不存在")

# 更新数据库

for field, value in user_in.model_dump(exclude_unset=True).items():

setattr(user, field, value)

db.commit()

# 失效缓存

invalidate_user_cache(user_id)

invalidate_users_list_cache()

return user

七、多级缓存

7.1 L1 + L2缓存

from collections import OrderedDict

import threading

class LRUCache:

"""LRU内存缓存"""

def __init__(self, max_size: int = 1000):

self.max_size = max_size

self.cache = OrderedDict()

self.lock = threading.Lock()

def get(self, key: str) -> Optional[Any]:

with self.lock:

if key not in self.cache:

return None

# 移到末尾(最近使用)

self.cache.move_to_end(key)

return self.cache[key]

def set(self, key: str, value: Any):

with self.lock:

if key in self.cache:

self.cache.move_to_end(key)

else:

if len(self.cache) >= self.max_size:

# 移除最久未使用

self.cache.popitem(last=False)

self.cache[key] = value

def delete(self, key: str):

with self.lock:

self.cache.pop(key, None)

L1: 内存缓存(快速)

l1_cache = LRUCache(max_size=1000)

L2: Redis缓存(持久)

l2_cache = Cache

class MultiLevelCache:

"""多级缓存"""

@staticmethod

def get(key: str) -> Optional[Any]:

# L1

value = l1_cache.get(key)

if value is not None:

return value

# L2

value = l2_cache.get(key)

if value is not None:

# 回写L1

l1_cache.set(key, value)

return value

return None

@staticmethod

def set(key: str, value: Any, expire: int = 300):

# L1

l1_cache.set(key, value)

# L2

l2_cache.set(key, value, expire=expire)

@staticmethod

def delete(key: str):

l1_cache.delete(key)

l2_cache.delete(key)

使用

MultiLevelCache.set("user:1", {"id": 1, "name": "Alice"})

user = MultiLevelCache.get("user:1")

八、实战案例

8.1 完整缓存系统

from fastapi import FastAPI, Depends, HTTPException

from fastapi.responses import Response

from pydantic import BaseModel

from sqlalchemy.orm import Session

from datetime import datetime

import hashlib

import json

app = FastAPI()

class User(BaseModel):

id: int

name: str

email: str

updated_at: datetime

class CacheManager:

"""缓存管理器"""

def __init__(self):

self.l1_cache = LRUCache(max_size=500)

self.l2_client = redis.Redis(host="localhost", decode_responses=True)

def _get_l2(self, key: str) -> Optional[dict]:

value = self.l2_client.get(key)

if value:

return json.loads(value)

return None

def _set_l2(self, key: str, value: dict, expire: int = 300):

self.l2_client.setex(key, expire, json.dumps(value))

def get(self, key: str) -> Optional[dict]:

# L1

value = self.l1_cache.get(key)

if value is not None:

return value

# L2

value = self._get_l2(key)

if value is not None:

self.l1_cache.set(key, value)

return value

return None

def set(self, key: str, value: dict, expire: int = 300):

self.l1_cache.set(key, value)

self._set_l2(key, value, expire)

def delete(self, key: str):

self.l1_cache.delete(key)

self.l2_client.delete(key)

def delete_pattern(self, pattern: str):

keys = self.l2_client.keys(pattern)

if keys:

self.l2_client.delete(*keys)

cache_manager = CacheManager()

@app.get("/api/users/{user_id}", response_model=User)

async def get_user(

user_id: int,

db: Session = Depends(get_db)

):

"""获取用户(多级缓存)"""

cache_key = f"user:{user_id}"

# 尝试从缓存获取

cached = cache_manager.get(cache_key)

if cached:

return User(**cached)

# 从数据库获取

user = db.query(UserModel).filter(UserModel.id == user_id).first()

if not user:

raise HTTPException(status_code=404, detail="用户不存在")

# 写入缓存

cache_manager.set(cache_key, user.model_dump(), expire=300)

return user

@app.get("/api/users", response_model=list[User])

async def get_users(

skip: int = 0,

limit: int = 20,

db: Session = Depends(get_db)

):

"""获取用户列表(带缓存)"""

cache_key = f"users:list:{skip}:{limit}"

cached = cache_manager.get(cache_key)

if cached:

return [User(**u) for u in cached]

users = db.query(UserModel).offset(skip).limit(limit).all()

if not users:

return []

cache_manager.set(cache_key, [u.model_dump() for u in users], expire=300)

return [User.model_validate(u) for u in users]

@app.post("/api/users")

async def create_user(user_in: UserCreate, db: Session = Depends(get_db)):

"""创建用户(失效缓存)"""

user = UserCreate(**user_in.model_dump())

db.add(user)

db.commit()

db.refresh(user)

# 失效缓存

cache_manager.delete_pattern("users:*")

return user

@app.put("/api/users/{user_id}")

async def update_user(

user_id: int,

user_in: UserUpdate,

db: Session = Depends(get_db)

):

"""更新用户(失效缓存)"""

user = db.query(UserModel).filter(UserModel.id == user_id).first()

if not user:

raise HTTPException(status_code=404, detail="用户不存在")

for field, value in user_in.model_dump(exclude_unset=True).items():

setattr(user, field, value)

db.commit()

# 失效缓存

cache_manager.delete(f"user:{user_id}")

cache_manager.delete_pattern("users:list:*")

return user

@app.delete("/api/users/{user_id}")

async def delete_user(user_id: int, db: Session = Depends(get_db)):

"""删除用户(失效缓存)"""

user = db.query(UserModel).filter(UserModel.id == user_id).first()

if not user:

raise HTTPException(status_code=404, detail="用户不存在")

db.delete(user)

db.commit()

# 失效缓存

cache_manager.delete(f"user:{user_id}")

cache_manager.delete_pattern("users:list:*")

return {"message": "删除成功"}

常见坑自查清单

现象自查方法修复方案
缓存穿透大量404检查空值缓存缓存空值标记
缓存击穿热点key失效检查并发请求加锁或互斥
缓存雪崩大量key同时失效检查过期时间随机过期时间
数据不一致缓存旧数据检查失效逻辑及时失效缓存
内存溢出OOM错误检查缓存大小设置最大容量

结语

关键洞察

  • 缓存能显著提升性能
  • 注意缓存穿透、击穿、雪崩
  • 多级缓存平衡速度与容量
  • 及时失效保证数据一致性

互动

  1. 1.你用Redis还是内存缓存?
  2. 2.遇到过缓存雪崩问题吗?
  3. 3.缓存命中率一般多少?
版本: V1.0 | 2026-05-26 | Python Web开发系列

📚 推荐阅读

📝 摘要:今天深入学习静态代码分析技术,这是安全审计的核心技能。从 Python AST 模块到检测模式设计,收获满满!

发布于 202603

01-Python 环境搭建与第一个脚本

发布于 202603

【优化】Python代码优化与调试技巧

发布于 202603

KEYWORDS

IL, Python, pip, 函数, 列表

💡 如果你觉得这篇文章有帮助,请点个在看,分享给更多需要的人!

📝 关注我,获取更多实用干货~

🤝 有问题欢迎评论区留言交流!

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-03 08:26:47 HTTP/2.0 GET : https://f.mffb.com.cn/a/498803.html
  2. 运行时间 : 0.090385s [ 吞吐率:11.06req/s ] 内存消耗:4,650.63kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=5795df333bb0db0f9a4bc80a8e4fe1e1
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000565s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000828s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000363s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000284s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000516s ]
  6. SELECT * FROM `set` [ RunTime:0.000200s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000594s ]
  8. SELECT * FROM `article` WHERE `id` = 498803 LIMIT 1 [ RunTime:0.001261s ]
  9. UPDATE `article` SET `lasttime` = 1783038407 WHERE `id` = 498803 [ RunTime:0.008198s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000247s ]
  11. SELECT * FROM `article` WHERE `id` < 498803 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000465s ]
  12. SELECT * FROM `article` WHERE `id` > 498803 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000620s ]
  13. SELECT * FROM `article` WHERE `id` < 498803 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.003549s ]
  14. SELECT * FROM `article` WHERE `id` < 498803 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.001794s ]
  15. SELECT * FROM `article` WHERE `id` < 498803 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.002221s ]
0.091968s