首页 \ 问答 \ as3 URLLoader缓存移动应用的建议(as3 URLLoader Cache suggestions for mobile app)

as3 URLLoader缓存移动应用的建议(as3 URLLoader Cache suggestions for mobile app)

我一直在寻找一个类来管理URLLoader调用中的数据缓存但是不成功。 URLLoader是否默认缓存?

我正在构建一个应用程序来获取用户的大量信息(个人资料详细信息,朋友列表,个人资料图像等),我不希望每次都调用URLLoader。 我在第一次加载时缓存他们的配置文件图像,并希望我可以对其余数据执行相同的操作,而无需在本地创建数据库的克隆。

干杯


I have been looking around for a class to manage the caching of the data from a URLLoader call but been unsuccessful. Does URLLoader cache by default?

I am building an app that fetches a bunch of information on the user (profile details, friend lists, profile image etc) and I would prefer not to call URLLoader each time. I am caching their profile image on first load and hope I can do the same with the rest of the data without having to create a clone of the DB locally.

Cheers


原文:https://stackoverflow.com/questions/17267015
更新时间:2022-10-30 18:10

最满意答案

使用orphanRemoval

@OneToMany(mappedBy="classroom", cascade={CascadeType.ALL}, orphanRemoval=true)

每当从持久集中删除条目时,它将被删除。 这意味着您需要使用持久集 。 即你不能更换套装,而应该做:

classroom.getRoster().clear();
classroom.getRoster().addAll(newRoster);

示例如何将持久集与用户所需的集同步:

/**
 * Assemble ClassroomUser relations.
 * @param classroom Classroom entity. Must be attached persistent or transient. Never null.
 * @param userIds Collection of user identifiers. Can be empty. Never null.
 */
private void assembleClassroomUsers(Classroom classroom, Collection<Integer> userIds) {
    // Make sure relation set exists (might be null for transient instance)
    if (classroom.getUsers() == null) {
        classroom.setUsers(new HashSet<ClassroomUser>());
    }
    // Create working copy of the collection
    Collection<Integer> ids = new HashSet<Integer>(userIds);
    // Check existing relations and retain or remove them as required
    Iterator<ClassroomUser> it = classroom.getUsers().iterator();
    while (it.hasNext()) {
        Integer userId = it.next().getUser().getId();
        if (!ids.remove(userId)) {
            it.remove(); // This will be picked by the deleteOrphans=true
        }
    }
    // Create new relations from the remaining set of identifiers
    for (Integer userId : ids) {
        ClassroomUser classroomUser = new ClassroomUser();
        classroomUser.setClassroom(classroom);
        // User must not have ClassroomUser relations initialized, otherwise Hibernate 
        // will get conflicting instructions what to persist and what to drop => error.
        // It might be safer to use dummy transient instance...
        User dummyUser = new User();
        dummyUser.setId(userId);
        classroomUser.setUser(dummyUser);
        classroom.getUsers().add(classroomUser);
    }
}

这种方法看起来有点复杂。 您可以使用自定义equals / hashCode和一些Set<E>操作方法(例如来自Guava)创建更简单(但可能不太多)的东西。


Use orphanRemoval:

@OneToMany(mappedBy="classroom", cascade={CascadeType.ALL}, orphanRemoval=true)

Whenever an entry is removed from the persistent set, it will get deleted. And this means you need to work with the persistent set. I.e. you are not allowed to replace the set, instead you should do:

classroom.getRoster().clear();
classroom.getRoster().addAll(newRoster);

EXAMPLE how to synchronize persistent set with a user required set:

/**
 * Assemble ClassroomUser relations.
 * @param classroom Classroom entity. Must be attached persistent or transient. Never null.
 * @param userIds Collection of user identifiers. Can be empty. Never null.
 */
private void assembleClassroomUsers(Classroom classroom, Collection<Integer> userIds) {
    // Make sure relation set exists (might be null for transient instance)
    if (classroom.getUsers() == null) {
        classroom.setUsers(new HashSet<ClassroomUser>());
    }
    // Create working copy of the collection
    Collection<Integer> ids = new HashSet<Integer>(userIds);
    // Check existing relations and retain or remove them as required
    Iterator<ClassroomUser> it = classroom.getUsers().iterator();
    while (it.hasNext()) {
        Integer userId = it.next().getUser().getId();
        if (!ids.remove(userId)) {
            it.remove(); // This will be picked by the deleteOrphans=true
        }
    }
    // Create new relations from the remaining set of identifiers
    for (Integer userId : ids) {
        ClassroomUser classroomUser = new ClassroomUser();
        classroomUser.setClassroom(classroom);
        // User must not have ClassroomUser relations initialized, otherwise Hibernate 
        // will get conflicting instructions what to persist and what to drop => error.
        // It might be safer to use dummy transient instance...
        User dummyUser = new User();
        dummyUser.setId(userId);
        classroomUser.setUser(dummyUser);
        classroom.getUsers().add(classroomUser);
    }
}

This approach might seem a little bit complex. You might be able to create something simpler (but probably not too much) with custom equals/hashCode and some Set<E> manipulation methods (e.g. from Guava).

相关问答

更多
  • 老实说,我不知道为什么,但如果您将CascadeType.PERSIST (或更好的CascadeType.ALL )添加到Provider实体中的@OneToMany关系,它将按预期工作。 可能Hibernate文档缺乏这个小细节。 用JPA2 更新 EclipseLink 2.5.1似乎没有这个问题 第二次更新 在第2.9节“实体关系”中,JPA 2.1规范说:“如果孤立的实体是分离的,新的或移除的实体,则orphanRemoval的语义不适用。” 我不知道你的相关实体是否被分离,但如果是的话,这不是一 ...
  • 明确的答案是:不,您的JPA提供商不可能自动处理您描述它的方式的双向关系。 但是,您可以实现在您的实体中设置双向关联的逻辑,或许可以沿着这些方向进行: class Department { public void addEmployee(Employee empl) { if (empl.getDepartment() != null && !this.equals(empl.getDepartment())) { empl.getDepartment().getEmployees ...
  • 如果您使用Hibernate,则必须明确定义CascadeType.DELETE_ORPHAN注释,可以与JPA CascadeType.ALL结合使用。 如果您不打算使用Hibernate,则必须明确地先删除子元素,然后删除主记录以避免任何孤立记录。 执行顺序 取出要删除的主行 获取子元素 删除所有子元素 删除主行 关闭会议 使用JPA 2.0,现在可以使用选项orphanRemoval = true @OneToMany(mappedBy="foo", orphanRemoval=true) If y ...
  • JPA的行为是正确的(意思是根据规范 ):对象不会被删除,因为您已经从OneToMany集合中删除它们。 有供应商特定的扩展,但本机JPA不适应它。 部分原因是因为JPA实际上并不知道是否应该删除从集合中删除的内容。 在对象建模术语中,这是组合与“聚合”之间的区别。 在组合中 ,没有父项的子实体没有存在。 房间和房间之间的一个典型的例子。 删除房子和房间也去。 汇总是一种较松散的协会,以课程和学生为代表。 删除课程,学生仍然存在(可能在其他课程)。 因此,您需要使用特定于供应商的扩展来强制此行为(如果可用) ...
  • 你有没有尝试过: team2.setPlayers(team1.getPlayers(); team1.setPlayers(null); for (Player player : team2.getPlayers() { player.setTeam(team2); } Have you tried: team2.setPlayers(team1.getPlayers(); team1.setPlayers(null); for (Player player : team2.getPlayers( ...
  • 这非常简单: customer.addOrder(order); 这就是你所需要的一切。 这是ORM的原则。 您操纵对象,ORM使用您定义的映射将它们保存在数据库中。 It's extremely simple: customer.addOrder(order); That's all you need. That's the principle of an ORM. You manipulate objects, and the ORM saves them in the database using ...
  • 是的,根据@jmvivo的回答你需要使用orphanRemoval = true是你的用例的解决方案,这里按照Oracle在这个链接 当从关系中移除一对一或一对多关系中的目标实体时,通常希望将移除操作级联到目标实体。 此类目标实体被视为“孤儿”,orphanRemoval属性可用于指定应删除孤立实体。 例如,如果订单包含多个订单项,并且其中一个订单项已从订单中删除,则已删除的订单项会被视为孤儿。 如果将orphanRemoval设置为true,则在从订单中删除订单项时,系统商品实体将被删除。 您可能还希望在 ...
  • 您需要另一个OneToMany关系:确保db表中的两列代表Feedback : author和receivee :它们将指向employee表的主键,因此它们必须具有相同的类型。 添加外键约束:它们都应指向employee表的主键。 然后,按照zbigniew的回答中的解释,用Java映射关系: 反馈类: @ManyToOne @JoinColumn(name="author") private Employee author; @ManyToOne @JoinColumn(name="receivee" ...
  • JPA没有这样做,据我所知,没有JPA实现可以做到这一点。 JPA要求您管理关系的两个方面。 当只更新关系的一侧时,这有时被称为“对象损坏” JPA确实在双向关系中定义了一个“拥有”的一方(对于OneToMany,这是没有mappedBy注释的一方),它用于在持久化到数据库时解决冲突(只有一个表示数据库中的关系与内存中的两个相比,因此必须做出解决方案)。 这就是为什么要实现对ProductOrder类的更改,而不是对Client类的更改。 即使拥有“拥有”关系,您也应该始终更新双方。 这通常会导致人们只依赖 ...
  • 使用orphanRemoval : @OneToMany(mappedBy="classroom", cascade={CascadeType.ALL}, orphanRemoval=true) 每当从持久集中删除条目时,它将被删除。 这意味着您需要使用持久集 。 即你不能更换套装,而应该做: classroom.getRoster().clear(); classroom.getRoster().addAll(newRoster); 示例如何将持久集与用户所需的集同步: /** * Assemble ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)