| 313 | } |
| 314 | |
| 315 | func (s *CacheHandler) ReadNode(ctx context.Context, in *tree.ReadNodeRequest, opts ...grpc.CallOption) (*tree.ReadNodeResponse, error) { |
| 316 | resp, e := s.Next.ReadNode(ctx, in, opts...) |
| 317 | if nodes.IsFlatStorage(ctx, "in") { |
| 318 | return resp, e |
| 319 | } |
| 320 | notFound := e != nil && errors.Is(e, errors.StatusNotFound) |
| 321 | tempo := e == nil && resp.Node.GetEtag() == "temporary" |
| 322 | out, isCached := s.cacheGet(ctx, in.Node.GetPath()) |
| 323 | if e == nil && resp.Node != nil { |
| 324 | // Check it was not recently removed |
| 325 | if parentDiff, ok := s.cacheDiff(ctx, path.Dir(in.Node.GetPath())); ok { |
| 326 | if _, o := parentDiff.Deletes[in.Node.GetPath()]; o { |
| 327 | return nil, errors.WithMessage(errors.NodeNotFound, "NotFound in cache") |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | if isCached && (notFound || tempo) { |
| 332 | return &tree.ReadNodeResponse{ |
| 333 | Node: out, |
| 334 | Success: true, |
| 335 | }, nil |
| 336 | } |
| 337 | |
| 338 | return resp, e |
| 339 | } |